Description:
Determine whether a number is prime.
Determine whether a number is prime.
C Code
#include <stdio.h>
#include <math.h>
int isPrime(int n) {
if (n < 2) return 0;
for (int i = 2; i <= (int)sqrt(n); i++)
if (n % i == 0) return 0;
return 1;
}
int main() {
printf("%d\n", isPrime(29));
return 0;
}
Expected Output
1 (true)