Algorithm to find reverse of a number

1. Start.

2. Initialize rev = 0 ,is_negative = 0.

3. Read number.

4. If number < 0, get absolute value of number is variable number and assign is_negative = 1.

5. While number > 0
      digit = number % 10;
      rev = 10 * rev + digit;
      number = number / 10;

6. If is_negative == 1, make rev negative.

7. Print reverse number.

8. End.

No comments:

Post a Comment