codescracker


c++

C++ Program to Reverse Number



« Previous Program Next Program »


Reverse Number in C++

To reverse a number in C++ programming, then you have to ask to the user to enter a number. Now, start reversing that number to find its reverse and then display its reverse on the screen. To reverse a number, first make a variable say rev and place 0 to rev initially, and make one more variable say rem. Now place the modulus of the number to rem and place rev*10+rem to rev, now divide the number with 10 and continue until number will become 0.

C++ Programming Code to Reverse Number

Following C++ program ask to the user to enter any number to find the reverse, then display the result on the screen :

/* C++ Program - Reverse Number */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	int num, rev=0, rem;
	cout<<"Enter a number : ";
	cin>>num;
	while(num!=0)
	{
		rem=num%10;
		rev=rev*10+rem;
		num=num/10;
	}
	cout<<"Reverse = "<<rev;
	getch();
}

When the above C++ program is compile and executed, it will produce the following result:

C++ program to reverse number

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test