Wednesday 17 August 2011

Program to identify the prime number


Code:
#include<stdio.h>
#include<conio.h>
void main()
{
      int num,flag=0,a;
            printf("Enter an integer: ");
            scanf("%d",&num);
      //Logic for prime number
            if(num==2)
                  printf("%d is Prime Number.",num); 
            else
            {
                  for(a=2;a<num;a++)
                  {
                        if(num%a==0)
                              flag=1;
                  }
            }
            if(flag==1)
                  printf("%d is not a Prime Number.",num);
            else
                  printf("%d is Prime Number.",num);
      getch();

}

Result:

Enter an integer: 8
8 is not a Prime Number.

If you have any confusion about that program, contact me freely :)


0 comments:

Post a Comment