-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLec7.cpp
66 lines (61 loc) · 1012 Bytes
/
Lec7.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Reverse integer
/*
#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
int digit;
int ans=0;
while(n!=0)
{
digit=n%10;
ans = (ans*10)+digit;
n=n/10;
}
cout<<ans;
}*/
// Reverse integer[range case]
/*
#include <iostream>
#include <climits>
using namespace std;
int main()
{
int n;
cin >> n;
int digit;
int ans = 0;
while (n != 0)
{
digit = n % 10;
ans = (ans * 10) + digit;
n = n / 10;
if ((ans > INT_MAX) || (ans < INT_MIN))
{
return 0;
}
}
cout << ans;
}
*/
// Power of 2 [then true] else [false]
#include <iostream>
#include <climits>
using namespace std;
int main()
{
int n;
cin >> n;
int ans = 1;
for (int i = 0; i <= 30; i++)
{
if (ans == n)
{
cout << "true";//return true;
}
if (ans < INT_MAX / 2)
ans = ans * 2;
}
cout << "false"; //return false
}