New Android apps UniqueKey

Sunday, 22 February 2015

Prime Number or not


/* A C program to check whether a number is prime or not. */

#include<stdio.h>

main()
{
  int n, i, c=0;
  
  printf("Enter the number to check whether this number is prime or not :  ");
  scanf("%d",&n);
  
  for(i=2;i<=n/2;i++)
  {
      if(n%i==0)
      {
          c=1;
          break;
      }
  }
  if (c==0)
      printf("%d is a prime number.",n);
  else
      printf("%d is not a prime number.",n);
}

No comments:

Post a Comment