Thursday 28 June 2012

c++ program that check whether enter number is prime or not

    #include<iostream.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    int n,m;
    cout<<"Please enter a number: ";
    cin>>n;
    for (int i=2;i<=(n-1);i++)
    {
    if(n%i==0)



    {
    cout<<"Not a prime";
    break;
    }
    else
    {
    cout<<"Prime";
    break;
    }
    }
    getch();
    }


No comments:

Post a Comment