Tag Archives: func

C++ || Snippet – How To Reverse An Integer Using Modulus & While Loop

This page will consist of a simple program which demonstrates how to reverse an integer (not an int array) using modulus and a while loop.

REQUIRED KNOWLEDGE FOR THIS SNIPPET

Functions
Modulus
While Loops


QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Once compiled, you should get this as your output
(Note: the code was compiled three separate times to display different output)

==== RUN #1 ====

Enter a number: 2012
2012 reversed is: 2102

==== RUN #2 ====

Enter a number: 1987
1987 reversed is: 7891

==== RUN #3 ====

Enter a number: 241
241 reversed is: 142