Monday, 12 December 2011

C program to check whether a number is prime or not


#include<stdio.h>

main()
 {
  int n,i,r,f=0;
  printf("Enter a number\n");
  scanf("%d",&n);
  if(n==1)
  printf("1 is neither prime nor composite\n");
  else
  {
  for(i=2;i<n;i++)
{
r=n%i;
if(r==0)
 {
 f=1;
 break;
 }
else
f=0;
}
  if(f==0)
  printf("It is a prime number\n");
  else
  printf("It is not a prime number\n");
  }
 }



You Like It!? Then kindly share with your Friends.
Comments
0 Comments

No comments:

Post a Comment