Check Whether Number is Prime or not


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<stdio.h>
#include<conio.h>
 
int main() {
   int num, i, count = 0;
 
   printf("Enter a number:");
   scanf("%d", &num);
 
   for (i = 2; i <= num / 2; i++) {
      if (num % i == 0) {
         count++;
         break;
      }
   }
 
   if (count == 0)
      printf("%d is a prime number", num);
   else
      printf("%d is not a prime number", num);
 
   getch();
}