basics · intermediate · ~15 min
Bounded loops and the √n trick.
Implement int is_prime(unsigned long n) returning 1 if n is prime, 0 otherwise. By convention, 0 and 1 are not prime.
int is_prime(unsigned long n) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.