C++ Program to Find Prime Number using Constructor

#include<iostream.h>
#include<conio.h>
class prime
{
int a,j,i;
public:
prime(int x)
{
a=x;
}
void calculate()
{
j=1;
{
for(i=2;i<=a/2;i++)
if(a%i==0)
{
j=0;
break;
}
else
{
j=1;
}
}
}
void show()
{
if(j==1)
cout<< "\nThis Number is prime Number!\n";
else
cout<<"\nThis Number is Not prime!\n";
}
};
void main()
{
int a;
cout<<"\nEnter any Number: "; cin>>a;
prime obj(a);
obj.calculate();
obj.show();
getch();
}

Output:
C++ Program to Find Prime Number using Constructor

Leave a Reply

Your email address will not be published. Required fields are marked *