-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7.c
More file actions
33 lines (25 loc) · 614 Bytes
/
7.c
File metadata and controls
33 lines (25 loc) · 614 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
/*
Problem 7 : 10001st Prime
By listing the first six prime numbers: 2,3,5,7,11 and 13, we can see that the 6th prime is 13.
What is the 10001st prime number?
Answer: 104743
*/
#include <stdio.h>
int main() {
int i, a = 2, count = 0;
while (count < 10001) {
int is_prime = 1;
for (i = 2; i < a; i++) {
if (a % i == 0) {
is_prime = 0;
break;
}
}
if (is_prime) {
count++;
}
a++;
}
printf("10001st prime number: %d\n", --a);
return 0;
}