# 10+ CPP Programs to Reverse a Number

This post contains a total of 10+ Hand-Picked C++ Programs to Reverse a Number with Source Codes. All the programs are made using C++ Programming Language.

You can use the source code of these programs for educational purpose with credits to the original owner.

### Related Posts

Click a Code to Copy it.

## 1. By echo \$name

Made by echo \$name. Simple program to reverse a number. ( Source )

```Enter a number to reverse 6574
Reverse of entered number is =4756```
``````#include <iostream>
using namespace std;

int main() {

int n, reverse = 0;

cout<<"Enter a number to reverse\n";
cin>>n;

while (n != 0)
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
/*taking unit place digit of no and moving to reverse
Dividing the no to discard unit place digit*/

cout<<"Reverse of entered number is ="<<reverse<<"\n";

return 0;
}``````

## 2. By tooselfish

Made by tooselfish. C++ program to reverse a number. ( Source )

```Your number input : 2445
The reverse number: 5442```
``````#include <iostream>

int main() {

int a, b, c = 0;

// input a whole integer
// for example: 2485
std::cin >> b;

// for input failure
if( std::cin.fail() ){
std::cerr << "Wrong input!\n";
return 1;
}

std::cout << "Your number input : " << b << std::endl;

// reverse the input
while (b != 0){
a = b % 10;
c = ( c * 10 ) + a;
b = b / 10;
}

// output the reverse
std::cout << "The reverse number: " << c << std::endl;

return 0;
}``````

## 3. By AliR૯za

Made by AliR૯za. ( Source )

```number you entered:::35435
reverse :::53453```
``````#include <iostream>
using namespace std;
int main()
{
unsigned long long num,rev=0;
cin>>num;
cout<<"number you entered:::"<<num<<endl<<"reverse :::";
while (num>0)
{
rev=num%10;
num=num/10;
cout<<rev;
}
}``````

## 4. By Sololearn

Made by Sololearn. ( Source )

`95487`
``````#include <iostream>
using namespace std;

int main()
{
//sample number
int n = 78459;

int reverse = 0;
while (n != 0)
{
// use modulus operator to strip off the last digit and create the reversed number
int rem = n % 10;
reverse = reverse * 10 + rem;
n /= 10;
}

cout << reverse << endl;

return 0;
}
``````

## 5. By Senan

Made by Senan. ( Source )

```2352
2532```
``````#include <iostream>
using namespace std;

int main() {
int x;
int a;
int rev;

rev =0;
cin>>x;// input the number
a=x;

cout <<x<<endl; // output the number

while(a>0){
rev=rev*10+a%10;
a=a/10;
} // reverse the number

cout <<rev ; // output the reversed number

return 0;
}``````

## 6. By Ritika

Made by Ritika. ( Source )

```225
522```
``````#include <iostream>
using namespace std;
void rev(int);

int main() {
int n;
cin >> n;
rev(n);
return 0;
}

void rev (int r)
{
int b;
for (int i= r; i >= 10; i /= 10)
{
b = r % 10;
cout<<b;
r /= 10;
}
cout<<r;
}``````

## 7. By YASH SHAH

Made by YASH SHAH. Basic C++ program to reverse a number. ( Source )

```Enter an Unsigned Integer: 567
Reverse Number is 765```
``````#include <iostream>
using namespace std;
/*Print the Entered Number in Reverse*/
int main()
{
unsigned int number,last_digit,reverse=0;
cout<<endl<<"Enter an Unsigned Integer:";
cin>>number;
do{
last_digit=number % 10;
reverse= reverse*10+last_digit;
number/=10;
}while(number>0);
cout<<endl<<"Reverse Number is "<<reverse;

return 0;
}``````

## 8. By Tanweer Ashif

Made by Tanweer Ashif. ( Source )

```Enter any number 67457
Reverse of the no.= 75476```
``````#include <iostream>
using namespace std;

int main()
{
int rev=0,num,i,r;
cout<<"Enter any number";
cin>>num;
for(i=num;i>0;i=i/10)
{
r=i%10;
rev=rev*10+r;

}

cout<<"\nReverse of the no.= "<<rev;

return 0;
}``````

## 9. By Hrishikesh Kulkarni

Made by Hrishikesh Kulkarni. ( Source )

```Enter number 346
reversed number is 643```
``````#include <iostream>
using namespace std;
int reverse(int n){
int d=0,c=0;
while (n > 0)
{
c=n%10;
d=d*10+c;
n=n/10;
}
return d;
}

int main() {
int a,res;
cout<<"Enter number ";
cin>>a;
cout<<a<<endl;
res=reverse(a);
cout<<"reversed number is "<<res;
return 0;
}
``````

## 10. By Bodan Talev

Made by Bodan Talev. ( Source )

```You've entered 8534.
The number in reverse is 4358.```
``````// Enter a number to reverse it.

#include <iostream>
#include <cstdlib>
using namespace std;

int main() {
int num,n;
int rev=0;

cin>>num;
cout<<"You've entered "<<num<<".\n";

while(num>0) {
n=num%10;
num=num/10;
rev=rev*10+n;
}
cout<<"The number in reverse is ";
cout<<rev<<".";

return 0;
}
``````

## 11. By SK

Made by SK. Reverse of any number using recursion. ( Source )

```Enter any number: 4764
Reverse of number 4764 is: 4674```
``````#include <iostream>
#include <math.h>

using namespace std;
int reverseNumber(int num);
int main()
{
int num, reverse;
cout<<"Enter any number: ";
cin>>num;

// Calling function to reverse any number
reverse = reverseNumber(num);

cout<<"Reverse of number "<<num <<" is: "<<reverse;

return 0;
}

//Recursive function to find reverse of any number

int reverseNumber(int num)
{
// Find total digits in num
int digit = (int) log10(num);

// Base condition
if(num == 0)
return 0;

return ((num%10 * pow(10, digit)) + reverseNumber(num/10));
}``````