Search & Find out

Sunday, December 6, 2009

PRIME OR NOT



#include "iostream.h"
#include "conio.h"
class prime
{
    private:
        int n;
    public:
        void accept ()
        {
            cout << "Enter a number: ";
            cin  >> n;
        }
        void cal ();
};
void prime :: cal ()
{
    if (n != 0 && n != 1)
    {
        for (int i=2; i
        {
            if (n%i == 0)
            {
                cout << "The number " << n << " is not a Prime number";
                break;
            }
        }
        if (i == n)
            cout << "The number " << n << " is a Prime number";
    }
    else
        cout << "The number " << n << " is neither Prime nor Composite";
}
void main ()
{
    clrscr ();
    prime P;
    cout<<"Welcome to find Prime no. or not\n\n";
    P.accept ();
    P.cal ();
getch ();
}



Get the executable ( .exe ) file for this program..
Download

0 comments:

Post a Comment

 

My Blog List

Term of Use