Skip to content

Commit 33237c1

Browse files
Add files via upload
1 parent 2d907ea commit 33237c1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Program to find all the prime numbers between two intervals using a function.
2+
3+
#include <stdio.h>
4+
5+
int isPrime (int number) {// ----------- create a function that checks if a number is prime or not
6+
7+
int flag = 0;// ------------------- create flag variable with value 0
8+
9+
for (int i = 2; i < number; i++) {
10+
if (number % i == 0) {// --- run loop from 2 to number - 1
11+
flag = 1;// ------- check if number is divisible by number between 2 to number - 1
12+
break;
13+
}
14+
else {
15+
flag = 0;
16+
}
17+
}
18+
if (flag == 0) {// ------- check if flag is 0 which is condition isolated for prime number
19+
printf("%d\n", number);// --- print prime number and add new line
20+
}
21+
}
22+
23+
int main() {
24+
25+
int x, y;
26+
scanf("%d %d", &x, &y);
27+
28+
for (int i = x; i <= y; ++i) {// run the loop from x to y
29+
isPrime(i);// for each iteration of loop call isPrime()
30+
}
31+
32+
return 0;
33+
}

0 commit comments

Comments
 (0)