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

Question #173522

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:46:50-0400
#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;
}

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