Answer:
#include<iostream>
using namespace std;
int main(){
int number;
cout<<"Enter the five-digit number: ";
cin>>number;
int result = 0;
while(number != 0){
int remainder = number % 10;
result = result*10 + remainder;
number = number/10;
}
cout<<"The reverse Number is: "<<result<<endl;
return 0;
}
Explanation:
first, include the library iostream for using the input/output.
Then, create the main function and declare the variables.
Print the message on the screen by using the instruction cout.
Store the value enter by the user in the variable by using cin instruction.
Take the while which runs until the number not equal to zero.
In the while, first, take the remainder of the number by using the operator '%'.
for example:
number = 123 % 10, it gives the value 3 which is the remainder.
after that, we write logic to reverse the number:
initially, remainder =3 and result=0
result = result * 10 + remainder
so, the result will be 3
after that, suppose remainder =2 and result=3 (previous calculated)
result = 3* 10 +2.
so, the result will be 32. so the number is reversed. we store the number in reverse order.
This process continues until the condition is true.
After that, print the output.