Friday, 11 December 2015

enter a number and reverse its digits using loop c++

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ long int n,num,digit,rev=0;
cout<<"Enter a number to reverse its digits "<<endl;
cin>>num;
n=num;
do
{ digit=num%10;
rev=(rev*10)+digit;
num=num/10;
}while(num!=0);
cout<<"reverse is "<<rev<<endl;
getch();
}

No comments:

Post a Comment