PRIME NUMBER

Muthumari_B · updated October 03, 2021 · C++
// PRIME Number Checking Program Using Class 
 
 
#include <iostream>
using namespace std;
class prime
{
    int n,i,c=0;
    public:
    void getdata();
    void check();
};
void prime::getdata()
{
    cout<<"\n PRIME  Number checking program;"<<endl;
    cout<<"\n Enter a Number : ";
    cin>>n;
    cout<<n<<endl;
}
void prime::check()
{
    if(n==0 || n==1)
    {
        cout<<n<<" is Neither Prime Nor Composite Number."<<endl;
        
    }    
    else
    {
        for(i=1;i<=n;i++)
        {
            if(n%i==0)
            {
               c++;
            }
        }    
        if(c==2)     
            cout<<n<<" is a PRIME Number."<<endl;
        else
            cout<<n<<" is Not a PRIME Number."<<endl;
    }
}
int main()
{
    prime n;
    n.getdata();
    n.check();
    return 0;
}

Comments

Please sign up or log in to contribute to the discussion.