what is prime number in c code example
Example 1: prime number c program
int isPrime(int n) {
for (int i = 2; i < n; i++) if (n % i == 0) return 0;
return 1;
}
Example 2: prime check in c
int isPrime(long long number) {
if (number == 0 || number == 1 || (number % 2 == 0 && number > 2)) {
return 0;
}
else {
for (long long i=3; i <= (long long)sqrt(number)+1; i++) {
if (number % i == 0) {
return 0;
}
}
return 1;
}
}