Tuesday, 26 January 2016

C++ Program to Reverse a Number

C++ Program to Reverse a Number

Hello friends, Today we will write a code for C++ Program to Reverse a Number.

C++ Program to Reverse a Number


It is very simple and easy to write code. The basic concept of this program is simply found the remainder of the number and again divide number by 10. In general reverse of 564 is 465.

Code for Reverse Program

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long n,rev=0,d;
cout<<"Enter any number:";
cin>>n;
while(n!=0)
{
d=n%10;
rev=(rev*10)+d;
n=n/10;
}
cout<<"Reversed of number is: "<<rev;
getch();
}

Output:

Enter any number: 435
Reverse of number is: 534

No comments:

Post a Comment