Implement a C++ program to define function named as ext, to extract the digits that located at even and odd position of five digit number and show the result.
#include <string>
#include <iostream>
using namespace std;
void ext(int x){
string str = to_string(x);
cout<<"Digits at even places are:\n";
for(int i = 0; i < str.length(); i++, i++)
cout<<str[i]<<" ";
cout<<"\nDigits at odd places are:\n";
for(int i = 1; i < str.length(); i++, i++)
cout<<str[i]<<" ";
}
int main(){
int n;
cout<<"Input number:\n";
cin>>n;
ext(n);
return 0;
}
Comments
Leave a comment