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 <iostream>
#include <string>
using namespace std;
void ext(int x){
string s = to_string(x);
cout<<"The digits at even positions are:\n";
for(int i = 0; i < s.length(); i++, i++)
cout<<s[i]<<endl;
cout<<"The digits at odd positions are:\n";
for(int i = 1; i < s.length(); i++, i++)
cout<<s[i]<<endl;
}
int main(){
int x;
cout<<"Enter a 5 digit number:\n";
cin>>x;
ext(x);
return 0;
}
Comments
Leave a comment