C Program to check whether the number is prime or not

#include<stdio.h>
int main()
{   
   int i,j,n;
   int flag=1;
   printf("Enter a number\n");
   scanf("%d",&n);
   for(i=2;i<n;i++)
   {
       if(n%i==0)
         {
          flag=0;
          break;
          }
  } 
  if(flag==1) 
   printf("%d is a Prime number\n",n);
   else
    printf("%d is not a Prime number\n",n);
}

Output:

C Program to check whether the number is prime or not

C Program to check whether the number is prime or not


Comments