C++ program to find prime number using constructor
#include<iostream>
using namespace std;
class prime
{
int n,i,c=0;
public:
prime(int x)
{
n=x;
}
void calculate()
{
for (i = 1; i <= n; i++ )
{
if ( n % i = = 0 )
{
c + + ;
}
}
}
void show()
{
if(c == 2 )
cout<< "\n It is a prime number.\n";
else
cout<<"\n It is not a prime number. \n";
}
};
int main()
{
int a;
cout<<"\n Enter any number to check : ";
cin>>a;
prime ob(a);
ob.calculate();
ob.show();
return 0;
}
1 Comments
Nice ☺️👍 keep going
ReplyDelete