Saturday, 22 August 2015

Write a C Program To Check Wheather Inputed Number is Prime Or Not

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

int main()
{
            int i,n,flag=0;    // declare variable i, n & flag and initialize flag with 0
            clrscr();

            printf("\n Enter the number : ");
            scanf("%d",&n);

            for(i=2;i<n;i++)
            {
                        if(n%i==0)
                        {
                                    flag=1;
                                    break;
                        }
            }

            if(flag==0)
            {
                        printf("\n %d is a Prime number",n);
            }
            else
            {
                        printf("\n %d ia not a Prime number",n);
            }

            getch();

            return 0;


}

No comments:

Post a Comment