Reverse a given number in C++

C++ Program to reverse a number . In this code, the given digits in the number will be reversed

Source code :

#include<iostream>

using namespace std;

int main(){

int number = 145; // Change the number to reverse
int reverse = 0;

while (number != 0)
   {
      reverse = reverse * 10;
      reverse = reverse + number%10;
      number  = number/10;
   }
 
cout<<"Reverse of given number is : " << reverse;

return 0;

}

Output :

Reverse of given number is : 541

Output :


                

Comments :