Write a program to enter any number from user and find the reverse of given number using for loop (example: 1234 » 4321)
#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;
}
Comments
Leave a comment