"KEEP LEARNING, DON'T STOP."
"KEEP LEARNING, DON'T STOP."
In this section you will learn reverse a numbers in c++ using loop. We will use three variable for reverse the numbers. Just simple mathematic operation we will perform to reverse the number. In this program we are taking the input from user.
Reverse mean shifting the first value to last value and shifting the last value to first value.
Let’s suppose a user will input a number ‘386’, then we will perform reverse operation on it.
#include<iostream.h> #include<conio.h> //REVERSE OF A NUMBER WITH LOOP void main() { int n, temp, rev = 0; clrscr(); cout<<"ENTER A NUMBER TO REVERSE:- "; cin>>n; temp = n; while(n != 0) { rev = rev *10; rev = rev + n%10; n = n/10; } cout<<"REVERSE OF IS:- "<<temp<<" "<<rev; getch(); }
ENTER A NUMBER TO REVERSE:- 386 REVERSE OF 465 IS:- 683