C++ Program to reverse number
We can reverse a number in C++ using loop and arithmetic operators. In this program, we are getting number as input from the user and reversing that number.
Let's see a simple C++ example to reverse a given number.
- #include <iostream.h>
- #include <conio.h>
- void main()
- {
- int n, reverse=0, rem;
- cout<<"Enter a number: ";
- cin>>n;
- while(n!=0)
- {
- rem=n%10;
- reverse=reverse*10+rem;
- n/=10;
- }
- cout<<"Reversed Number: "<<reverse<<endl;
- getch();
- }
Output:
Enter a number: 234 Reversed Number: 432
0 Comments