1#include<stdio.h>
2main() {
3 int n, i, count=0;
4 printf("Enter Number");
5 scanf("%d",&n);
6
7 for ( i = 1; i<= n; i++) {
8 if (n % i == 1) {
9 count++;
10 }
11 }
12 if( count == 2) {
13 printf("Prime Number");
14 }
15 else {
16 printf("Not A Prime Number");
17 }
18}
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
1int isPrime(int n) {
2 for (int i = 2; i < n; i++) if (n % i == 0) return 0;
3 return 1;
4}
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