Program to find reverse of the number

0 Suresh Chand March 28, 2021

In this example, We will learnt to find reverse of any number using C++ programming language.

To understand this example, We must have knowledge on following topics

To do this program, First we will take integer from user.

Then, We will loop number checking condition that number is equal to zero.

We will find remainder dividing by 10 and set to remainder variable

And also We will multiply previous reverse variable by 10 and add that remainder that we just obtained above. On this way we will find the reverse of any number using c++ programming langauge.

Let’s look an example to make clear concepts.

#include <iostream>
using namespace std;

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

    cout << "Enter an integer: ";
    cin >> n;

    while(n != 0) {
        rem = n % 10;
        rev = rev * 10 + rem;
        n /= 10;
    }

    cout << "Reversed Number = " << rev;

    return 0;
}

The output of above program is

Enter an integer: 123
Reverse Number  = 321
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Join Our Newsletter Now

Get the latest tutorials, examples and projects updates.

Ads Block Detector Powered by codehelppro.com

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Disable Ad Block

Want Same System