Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <stdio.

h>

int main() {
int n, i, isPrime = 1;

printf("Enter a positive integer: ");


scanf("%d", &n);

if (n <= 1) {
isPrime = 0;
} else {
for (i = 2; i <= n / 2; i++) {
if (n % i == 0) {
isPrime = 0;
break;
}
}
}

if (isPrime == 1) {
printf("%d is a prime number.\n", n);
} else {
printf("%d is not a prime number.\n", n);
}

return 0;
}

input: Enter a positive integer: 13


Output: 13 is a prime number.

input: Enter a positive integer: 16


Output: 16 is not a prime number.

You might also like