Reverse a number - C++ Program

Q. Write a C++ program to reverse a number.

Answer:

Following program is displaying the reverse number.

#include<iostream>
using namespace std;
int main()
{
        int num, rev=0, rem;
        cout<<"\n Enter Number : ";
        cin>>num;
        while(num!=0)
        {
                rem=num%10;
                rev=rev*10+rem;
                num=num/10;
        }
        cout<<"\n Reverse Number is : "<<rev;
        return 0;
}


Output:

reverse number