c-repl/example/primes.c
2024-01-18 12:00:34 +01:00

21 lines
340 B
C

int is_prime(int num) {
if (num <= 1) return 0;
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) return 0;
}
return 1;
}
int max_prime(int limit) {
int prime = 0;
for (int i = 1; i < limit; i++) {
if (is_prime(i)) {
prime = i;
}
}
return prime;
}
max_prime(250);