Navigation

Friday, 27 February 2015

Check whether the input number is prime or not

I am going to post a program by which itcan be checked  whether the input number is prime or not.

main()
{
    int a,c=0,i,n;
    clrscr();
    printf("enter the number to be checked :");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        a=n%i;
        if(a==0)
        {
            c=c+1;
        }
    }
    if (c==2)
    {
        printf("the given number is prime");
    }
    else
        printf("the given number is not prime");
    getch();
}

No comments:

Post a Comment