Reverse a number

    Last updated November 30, 2026

    Take the last digit, append it to a new number, and drop it from n, until n is 0. The chart assumes n is a non-negative integer. FlowSimp is completely free to use — no sign-up required.

    See the flowchart

    What does the flowchart look like?

    Ready to draw?

    No signup. Opens instantly in your browser.

    See the flowchart

    What is the matching code?

    Pseudocode

    read n
    reversed = 0
    while n > 0
      reversed = reversed * 10 + n mod 10
      n = integer quotient of n / 10

    Python

    def reverse_number(n):
        reversed_n = 0
        while n > 0:
            reversed_n = reversed_n * 10 + n % 10
            n //= 10
        return reversed_n

    C

    int reverse_number(int n) {
      int reversed = 0;
      while (n > 0) {
        reversed = reversed * 10 + n % 10;
        n /= 10;
      }
      return reversed;
    }
    • 123 becomes 321. 100 becomes 1, because the trailing zeros are not stored in the integer.
    • 0 stays 0, because the loop does not run. A negative n is outside this chart.