-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheuler7.c
More file actions
46 lines (40 loc) · 866 Bytes
/
euler7.c
File metadata and controls
46 lines (40 loc) · 866 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
#include <stdio.h>
#include <math.h>
int isPrime(int x){
double sqrtX = sqrt(x);
int testValue = 2;
int prime = 1;
while (testValue <= sqrtX and prime == 1){
if (x % testValue == 0){
prime = 0;
}
else {
if (testValue == 2){
testValue = testValue + 1;
}
else{
testValue = testValue + 2;
}
}
}
return(prime);
}
int getNthPrime(int n){
int counter = 1;
int testValue = 1;
int currentPrime;
while (counter < n){
testValue = testValue + 2;
currentPrime = isPrime(testValue);
if (currentPrime == 1){
counter = counter++;
}
}
return(testValue);
}
int main(){
int result;
result = getNthPrime(10001);
printf("%d", result);
return(0);
}