+ 4

How to reverse any number entered by user?

19th Jun 2017, 3:20 AM
Sarthak
Sarthak - avatar
4 odpowiedzi
19th Jun 2017, 3:24 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 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.
19th Jun 2017, 3:37 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
In Python you could just say print(input()[::-1])
20th Jun 2017, 9:37 PM
David Ashton
David Ashton - avatar
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;
19th Jun 2017, 3:41 AM
G.S.N.V. Suraj
G.S.N.V. Suraj - avatar