forked from manishaparuthi/manisha_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreversenum.cpp
49 lines (45 loc) · 866 Bytes
/
reversenum.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using namespace std;
#include<iostream>
int countDigit(int x)
{
int count =-1;
while(x!=0)
{
count++;
x=x/10;
}
return count;
}
int power(int base,int exp)
{
int result=1;
for(int i=0;i<exp;i++)
{
result=result*base;
}
return result;
}
int reversel (int x)
{
int reverse=0;
int n;
n=countDigit(x);
int temp;
while(n!=-1)
{
temp=x%10;
cout<<temp;
reverse=reverse+(temp*power(10,n));
n--;
x=x/10;
}
return reverse;
}
int main()
{
cout<<"Enter number: ";
int number;
cin >>number;
cout<<endl<<"Revverse is: "<<reversel(number);
return 0;
}