Wednesday, February 3, 2010

c program for checking prime number

The following code is used check out whether the given number is prime number or not .

void main()
{
     int a,i,j=0;
     printf("Enter the given number");
     scanf("%d",&n);
     if(i>2)//handling test case for number<2
     {
          for(i=2, i less than n ,i++)
         { if(n%i==0)

             {
                  j=1;

                  break;
          }
      }
     if(j==0)
         printf("Given number is prime");
     else
         printf("Given number is not prime number");
}