-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoops.cpp
More file actions
60 lines (53 loc) · 1.14 KB
/
Copy pathLoops.cpp
File metadata and controls
60 lines (53 loc) · 1.14 KB
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
#include<iostream>
using namespace std;
int main(){
//while loop
// int n=20;
// int count = 1;
// while (count <= n) {
// cout << count << endl;
// count++;
// }
//for loop
// int n=15;
// for (int i = 1; i <= n; i++){
// cout<<i<<endl;
// }
//Que: Sum of n numbers
// int n=5;
// int sum = 0;
// for (int i = 1; i <= n; i++){
// sum = sum + i;
// }
// cout<<"Sum ="<<sum<<endl;
//Que: Sum of all odd no.
// int n = 20;
// int sum = 0;
// for(int i=1; i<=n; i++){
// if(i%2 == 0){
// sum = sum + i;
// }
// }
// cout<<"Sum ="<<sum<<endl;
//do while
// int n = 5;
// int i = 1;
// do{
// cout<<i<<" ";
// i++;
// } while (i <= n);
//Que: Prime or not
int n = 5;
bool isPrime = true;
for(int i=2; i <= n-1; i++){
if(n%i == 0){
isPrime = false;
break;
}
}
if(isPrime == true){
cout<<"Prime"<<endl;
}else{
cout<<"Not Prime"<<endl;
}
}