-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass711.cpp
executable file
·61 lines (40 loc) · 936 Bytes
/
Class711.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
//============================================================================
// Name : Classroom1.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
int mypower(int n, int i) {
if (i < 0) {
return -1;
}
int result = 1;
while (i > 0) {
result = n * result; //result *= n
i--;
}
return result;
}
int square(int n) {
return n * n;
}
int main() {
int val = mypower(2, -4);
if (val < 0) {
cout << "Error"<< endl;
} else {
cout << "Result " << val << endl;
}
cout << "2 ** -4 " << mypower(2, -4) << endl;
// cout << "5 ** 0 " << mypower(5, 0) << endl;
/* int cnt = 1;
while (cnt <= 10) {
cout << cnt << " " << square(cnt) << endl;
cnt = cnt + 1; //cnt += 1 or cnt++
}
*/
return 0;
}