c-repl/example/primes.c

22 lines
342 B
C
Raw Normal View History

2024-01-12 13:37:52 +01:00
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);;