Check Whether Number Is Prime or not

Check Whether Number Is Prime or not

#include<stdio.h>

int main()
{

int num, i, count = 0;

   printf("Enter a number:\n");
   scanf("%d", &num);   //input from user

   for (i = 2; i <= num / 2; i++)
 {
      if (num % i == 0)
     {
         count++;
         break;
      }
   }

   if (count == 0)
      printf("%d is a prime number\n", num);   //Print Output On screen

   else
      printf("%d is not a prime number\n", num);   //Print Output On screen

}

Related Posts