Reversing The Number Of The Digit

Princy Prakash
1 min readMay 11, 2023

--

ALGORITHM:

  1. Get the input “n” from the user.
  2. Initialize a variable “rev_number” to 0.
  3. Repeat the following until “n” is greater than 0:
  • a) Find the remainder of “n” when divided by 10, and store it in a variable called “remainder”.
  • b) Multiply the current value of “rev_number” by 10, and add the value of “remainder” to it.
  • c) Divide “n” by 10 and store the result back in “n”.

4.Print out the value of “rev_number”.

DETAILED EXPLANATION:

1.This algorithm takes an input number “n” and reverses its digits.

2.It does this by repeatedly finding the last digit of “n” using the modulo operator (%), adding it to a variable “rev_number” after shifting the current value of “rev_number” one place to the left (i.e., multiplying it by 10), and then removing the last digit of “n” by dividing it by 10.

3. When “n” becomes 0, the reversed number is stored in “rev_number”, which is then printed out.

FLOWCHART:

--

--

Princy Prakash
Princy Prakash

Written by Princy Prakash

Hi I Am Princy. I recently discovered my passion for programming and excited to get deeper into the world of technologies also in problem-solving

No responses yet