You can flip an integer in either of the following ways: sequential flip and recursive flip.
Overflow is not considered here
Recursion enables reverse processing, that is, processing from the lowest end of the recursive stack, which can be obtained through drawing.
For Rec (Num/10 ):
12345
1234
123
12
1 <-- recursion makes this first Process
Package recursion; public class reverse_digits_of_a_number {public static void main (string [] ARGs) {int num = 123; system. out. println (reverse (Num); system. out. println (Rec (Num);} public static int reverse (INT num) {int REV = 0; while (num! = 0) {REV = rev * 10 + num % 10; num/= 10; // 10 shifts one digit to the right in decimal format} return Rev ;} static int revnum = 0; static int base = 1; public static int Rec (INT num) {If (num = 0) {return num;} Rec (Num/10 ); // It is equivalent to the block here until the recursion ends, for example, num = 123-> 12-> 1-> 0 revnum = revnum + base * (Num % 10 ); base * = 10; return revnum ;}}
Http://www.geeksforgeeks.org/write-a-c-program-to-reverse-digits-of-a-number/