C++ Program to find the Reverse of a Number
Program to find the Reverse of a Number
Here we will discuss how to find the reverse of a given number using C++ programming
To find the reverse of a number we will use loop and arithmetic operators(%, / ).
Let’s take an example for example:
Let’s see how the code works
- The user gives an input.
- The input will be stored in an int type variable say num
- A do while loop is started
- Modulus(%) of num is founded with 10 and stored in an int type variable say rem.
- An int variable reverse(initialised at 0) is multiplied by 10 and rem is added to it and the result is stored in reverse itself.
- num is divided by 10 and the value is stored in num itself.
- The loop works until num is not equal to 0.
- reverse is printed as output as it is the reverse of the number entered by the user.
//Reverse of a number
using namespace std;
int num, reverse=0, rem;
cout<<"Enter a number: ";
//loop to find reverse number
cout<<"Reversed Number: "<<reverse;
Enter a number: 1098
Reversed Number: 8901