-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2-29.cpp
More file actions
57 lines (53 loc) · 892 Bytes
/
Copy path2-29.cpp
File metadata and controls
57 lines (53 loc) · 892 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
using namespace std;
int main(){
int i = 0, j = 0;
bool isPrime = true;
cout << "using while(...){..} method:" << endl;
while(i < 100){
isPrime = true;
i++;
j = 2;
while(j < i){
if(i % j == 0){
isPrime = false;
break;
}
j++;
}
if(!isPrime) continue;
cout << i << ',';
}
cout << endl;
cout << "using do{...}while(...); method:" << endl;
i = 0, j = 0;
do{
isPrime = true;
i++;
j = 1;
do{
j++;
if(i != j and i % j == 0){
isPrime = false;
break;
}
}while(j < i);
if(!isPrime) continue;
cout << i << ',';
}while(i < 100);
cout << endl;
cout << "using for(...;...;...;){...} method:" << endl;
i = 0, j = 0;
for(i = 1;i<=100;i++){
isPrime = true;
for(j = 2;j < i; j++){
if(i % j == 0){
isPrime = false;
break;
}
}
if(!isPrime) continue;
cout << i << ',';
}
cout << endl;
}