Answer to Question #259037 in C++ for Charmaine

Question #259037

Write a program to enter any number from user and find the reverse of given number using for loop (example:  1234 » 4321)


1
Expert's answer
2021-11-01T02:51:20-0400
#include <iostream>


using namespace std;
int reverseDigits(int no){
static int rev_no=0;
static int base_position=1;
if(no>0){
    reverseDigits(no /10);
    rev_no +=(no%10)*base_position;
    base_position*=10;
}
return rev_no;
}


int main()
{
    int no;
    cout << "Enter numbers" << endl;
    cin>>no;
    cout << "The reverse of  numbers is:  " << reverseDigits(no);
    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