Monday 9 January 2012

Check Whether a Number is Prime or not

#include<stdio.h>
#include<conio.h>

void main()
{
    int n,i,flag=0;
    clrscr();
    printf("Enter the number::\n");
    scanf("%d",&n);
    for(i=2;i<=n/2;i++)
    {
        if(n%i==0)
        {
            flag=1;
        }
    }
    if(flag==1)
    {
        printf("Not Prime\n");
    }
    else
    printf("Prime");
    getch();
}

No comments:

Post a Comment