1int isPrime(long long number) {
2
3 if (number == 0 || number == 1 || (number % 2 == 0 && number > 2)) {
4 return 0;
5 }
6
7 else {
8 for (long long i=3; i <= (long long)sqrt(number)+1; i++) {
9 if (number % i == 0) {
10 return 0;
11 }
12 }
13 return 1;
14 }
15}
1#include <stdio.h>
2int main() {
3 int n, i, flag = 0;
4 printf("Enter a positive integer: ");
5 scanf("%d", &n);
6
7 for (i = 2; i <= n / 2; ++i) {
8
9 // condition for non-prime
10 if (n % i == 0) {
11 flag = 1;
12 break;
13 }
14 }
15
16 if (n == 1) {
17 printf("1 is neither prime nor composite.");
18 }
19 else {
20 if (flag == 0)
21 printf("%d is a prime number.", n);
22 else
23 printf("%d is not a prime number.", n);
24 }
25
26 return 0;
27}
28