-
Notifications
You must be signed in to change notification settings - Fork 0
/
prime_sieve.c
75 lines (57 loc) · 1.37 KB
/
prime_sieve.c
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
/* This is a simple 'is it prime' tester that I'm going to use to try out sonarlint, sonarQube and SonarCloud a bit
#
# I'm not going to try and make this clever initially
#
# Future additions:
#
# To test N:
# - Only test whether the prime numbers up to sqrt(N) divide into N without remainder
# - Use previously saved results to short circuit the test (for now I'll just test as if we have no known data)
#
# Save state between runs:
# - Save the list of primes you know about to disk for future runs
#
# Other extensions:
# - Ask user for N to test
# - Go and look up how people do this for real
*/
// TODO
// FIX
int is_prime(int number_to_test)
{
int false = 0;
int true = 1;
int prime = true;
int always_true = true;
int max_test = number_to_test/2;
int i = 2;
int bob;
bob++;
if(!always_true)
{
printf("Well this is embarassing\n");
}
while ((i <= max_test) && (prime == true) && always_true) // interestingly, SonarLint doesn't catch use of & True here
{
if( number_to_test % i == 0)
{
prime = false;
}
i++;
}
return prime;
}
int main()
{
// N to test
int N = 50;
for(int i = 2; i<N; i++)
{
if(is_prime(i))
{
printf("%d is prime\n", i);
}
}
return(0);
}