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
1#include <stdio.h>
2int main()
3{
4 int i, num, p = 0;
5 printf("Please enter a number: \n");
6 scanf("%d", &num);
7 for(i=1; i<=num; i++)
8 {
9 if(num%i==0)
10 {
11 p++;
12 }
13 }
14 if(p==2)
15 {
16 printf("Entered number is %d "\
17 "and it is a prime number.",num);
18 }
19 else
20 {
21 printf("Entered number is %d "\
22 "and it is not a prime number.",num);
23 }
24}
25