int isPrime(int n, int i) { if (n <= 2) { return (n == 2) ? 1 : 0; }
if (n % i == 0) { return 0; } if (i * i > n) { return 1; } return isPrime(n, i + 1);
}
int main() { int n;
printf("Enter a natural number: "); scanf("%d", &n); if (isPrime(n, 2)) { printf("%d is a prime number.\n", n); } else { printf("%d is not a prime number.\n", n); } return 0;
}
/* Пример работы программы: Enter a natural number: 17 17 is a prime number.
Enter a natural number: 24 24 is not a prime number. */
int isPrime(int n, int i) {
if (n % i == 0) {if (n <= 2) {
return (n == 2) ? 1 : 0;
}
return 0;
}
if (i * i > n) {
return 1;
}
return isPrime(n, i + 1);
}
int main() {
printf("Enter a natural number: ");int n;
scanf("%d", &n);
if (isPrime(n, 2)) {
printf("%d is a prime number.\n", n);
} else {
printf("%d is not a prime number.\n", n);
}
return 0;
}
/* Пример работы программы:
Enter a natural number: 17
17 is a prime number.
Enter a natural number: 24
24 is not a prime number. */