-
Notifications
You must be signed in to change notification settings - Fork 181
Expand file tree
/
Copy pathreverse_num.cpp
More file actions
41 lines (37 loc) · 958 Bytes
/
reverse_num.cpp
File metadata and controls
41 lines (37 loc) · 958 Bytes
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
#include <iostream>
using namespace std;
#include <cmath>
int digits( int n){ int c=1;
for ( int i=1; 5; i++)
{
if (n/pow(10,i)<1)
{
break;
}
else c++;
}
return c;
}
int main()
{
int n;
cin >> n;
cout<<digits(n)<<"\n";
int rev = 0;
for (int i = digits(n); n>=1; i--)
{
int x = n % 10;
rev += x *(pow(10, i-1));
n = n / 10;
}
cout << rev; /*
1234
4
4000
123
3
4300
4320
*/
return 0;
}