Reverse a number in c++

Reverse a number in c++


#include <iostream>

using namespace std;

int main()
{
    
    int originalNumber, reverseNumber = 0 , reminder = 0 ;
    cout<<"Enter a number ";
    std::cin >> originalNumber;
    
    while(originalNumber != 0){
        reminder = originalNumber % 10;
        reverseNumber = reverseNumber*10 + reminder;
        originalNumber = originalNumber/10;
    }
    
    cout<< reverseNumber;

    return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *