Skip to main content

Flowchart to reverse integer

Short answer

Repeatedly extract the last digit with N mod 10, build the reversed number as REV = REV*10 + digit, and set N = N/10 until N becomes 0. For 12345 the reversed output is 54321.

Draw a flowchart to find the reverse of an integer number. For example, 12345 is an integer number and its reverse is 54321.

The digits are taken one by one from the right using N mod 10 and added to the reversed number after multiplying it by 10.

        ( Start )
            |
       / Read N /
            |
        [ REV = 0 ]
            |
     +----->|
     |      v
     |  < N > 0 ? >--No--> / Print REV / --> ( Stop )
     |      | Yes
     |  [ R = N mod 10 ]
     |  [ REV = REV*10 + R ]
     |  [ N = N div 10 ]
     +------+

Dry run for N = 12345:

NRREV
1234555
1234454
1233543
1225432
1154321
0stop54321

Output: 54321.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 2 questions →