- 2069 Chaitra · 3 marks
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:
| N | R | REV |
|---|---|---|
| 12345 | 5 | 5 |
| 1234 | 4 | 54 |
| 123 | 3 | 543 |
| 12 | 2 | 5432 |
| 1 | 1 | 54321 |
| 0 | stop | 54321 |
Output: 54321.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Algorithm and flowchart help; Armstrong flowchart · Computer Programming, chapter 2
- Reverse a string using functions · Computer Programming, chapter 7 · asked 2×
- Check triangular number · Computer Programming, chapter 5
- Algorithm for numbers divisible by 9 not 6 · Computer Programming, chapter 2
- Palindrome check in FORTRAN · Computer Programming, chapter 11
- Sum of digits until single digit · Computer Programming, chapter 5 · asked 2×
- Prime number checking processor · Embedded System, chapter 2