Thursday, 27 October 2011

C program to check a number is prime or not

WRITE A PROGRAM TO CHECK WHETHER A NUMBER IS PRIME OR NOT





#include<stdio.h>
#include<conio.h>
void main()
{
 int n,i,x=0;
 printf("Enter a number:");
 scanf("%d",&n);
 for(i=2;i<=n;i++)
 {
  if(n%i==0)
  x=x+1;
 }
 if(x>1)
  printf("The number is not prime:");
 else
  printf("The number is prime:");
 getch();
}


Output:
   Enter a number:49
   The number is not prime

No comments:

Post a Comment