Reverse number program by C++

Reverse number program will reverse the position of all the digits of the given number. In this guide we will see C++ program to reverse a number. We will take the number from user and reverse it. If the user gives a number 753 then after reversing the number will be 357. Then we will print the result.

In C programming we have discussed several C program to reverse a number. Here, we will do same thing with C++ language. Let’s see the program bellow to reverse a number using C++.

C++ program to reverse a number

At first we will take the number and store it to main_num variable. Then we will use while loop to continue until the number is not equal to zero. Inside the while loop we have implemented our logic to reverse the number.

// c++ program to reverse a number

#include <iostream>
using namespace std;

int main(){
    int main_num, reverse_num = 0, reminder;

    cout << "Enter the integer to reverse it : ";
    cin >> main_num;

    while(main_num != 0){
        reminder = main_num % 10;
        reverse_num = reverse_num * 10 + reminder;
        main_num /= 10;

    cout << "\nNumber after reversing is = " << reverse_num << endl;

    return 0;


Output of reverse number program


Previous pageSum of digits

Next pageSwap numbers