Prime Using Class.cpp

Kali26 · September 23, 2020 · C++
#include <iostream>
using namespace std;
class number
{
    int a,i,c=0;
    public:
    void getdata();
    void check();
};
void number::getdata()
{
cout<<"\n Enter a number:";
cin>>a;
}
void number::check()
{
    for(i=1;i<=a;i++)
    {
        if(a%i==0)
        {
            c=c+1;
        }
    }
    if(c==2)
    {
    cout<<"\n The given number is a prime number";
    }
    else
    {
    cout<<"\n The given number is not a prime";
    }
}
int main()
{
    
    number n;
    
    cout<<"\n CHECKING OF PRIME OR NOT";
    cout<<"\n ≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈";
    n.getdata();
    n.check();
    return 0;
}

Comments

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