Friday, 5 July 2013

Write a program to reverse a number.

#include<iostream>
using namespace std;
int main()
{
long int a,num,div,mod;
a=0;
cout<<"Enter any positive integer: ";
cin>>num;
while(div!=0)
{
mod=num%10;
div=num/10;
num=num/10;
a=a*10+mod;
}
cout<<"The reverse of the integer is : "<<a;

}

No comments:

Post a Comment