C++ program to find reverse of a number. - coderforcoders

Search

Wednesday, 13 March 2019

C++ program to find reverse of a number.

#include<iostream>
using namespace std;
class reverse{
public:
int num,rev=0,rem,temp;
void findRev()
{
temp=num;
do
{
rem=temp%10;
rev=(rev*10)+rem;
temp=temp/10;
}
while(temp);
cout<<"Reverse of the number is "<<rev;
}
};
int main()
{
reverse obj1;
cout<<"Please enter a number \n";
cin>>obj1.num;
obj1.findRev();
cout<<endl;
}


Output 1:
Please enter a number
234
Reverse of the number is 432

Output 2:
Please enter a number
102
Reverse of the number is 201

Output 3:
Please enter a number
1234
Reverse of the number is 4321



No comments:

Post a Comment