Write a program to reverse a given number.
PROGRAM
#include <iostream.h>
#include <conio.h>
void main() {
clrscr();
long int num1,num2=0,r;
cout<<"Enter number to reverse: ";
cin>>num1;
cout<<"\nThe reversed number: ";
while(num1>0) {
r=num1%10;
num2=num2*10+r;
num1=num1/10;
}
cout<<num2;
getch();
}//end of the program
No comments:
Post a Comment