+ 4
How to reverse any number entered by user?
4 Answers
+ 2
Basically the algorithm is:
Find the last digit.
Multiply the initial answer var by 10 then add the last digit.
Divide initial number by 10 and ignore remainder.
Repeatthis until your initial number is reduced to 0.
+ 2
In Python you could just say
print(input()[::-1])
0
Logic is
//num is the entered number to be reversed
int rev = 0, s = 0,base = 1;
while(num != 0){
s = num%10;
rev = rev + s*base;
base = base*10;
num = num/10;
}
cout<<rev;