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.
Runtime Input :
00156
Output :
016
05
#include <string>
#include <iostream>
using namespace std;
void ext(int x){
    string str = to_string(x);
    cout<<"0";
    for(int i = 0; i < str.length(); i++, i++)
        cout<<str[i];
       
    cout<<"\n0";
    for(int i = 1; i < str.length(); i++, i++)
        cout<<str[i]<<endl;
}
int main(){
    int n;
    cout<<"Runtime Input:\n";
    cin>>n;
    cout<<"Output:"<<endl;
    ext(n);
    return 0;
}
Comments