C Program to check prime numbers

Simple C program to check prime numbers: Prime number is a number which is divisible only by one and itself. For example number 8 is not prime number because it is divisible by 1,2,4 and 8. But number 17 is prime number because it is divisible by only 1 and 17.
#include<stdio.h>
int main()
{
 int n,i,c=0;
 printf("Enter a number: ");
 scanf("%d",&n);
 if(n==1)
  printf("Not prime number\n");
 if(n==2)
 printf("Prime number\n");
 if(n>2)
 {
  for(i=2;i<n;i++)
  {
   if(n%i==0)
   {
   printf("Not prime number\n");
   c=0;
   break;
  }
  else
  {
   c=1;
  }
  }
 }
  if(c==1)
  printf("Prime number\n");
  return 0; 
}



Popular posts from this blog