Assignments » Flow Of Control » Set2 » Solution 5

Write a program to reverse any given integer number.

 

#include<iostream>
using namespace std;

int main()
{
	int n,t,r,rev=0;
	cout<<"Enter any number : ";
	cin>>n;
	t=n;

	while(t>0)
	{
		r=t%10;
		t=t/10;
		rev=rev*10+r;
	}

	cout<<"Reverse of number "<<n<<" is "<<rev;


	return 0;
}

 

 

Enter any number : 6329
Reverse of number 6329 is 9236

 

«back