Answer to Question #173877 in C++ for Vijay Raj

Question #173877

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.


1
Expert's answer
2021-03-21T04:47:06-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS