Math, asked by maddy5630, 10 months ago

write the c++ program to print the prime number using class&object

Answers

Answered by bossrc64p7l5et
0
Hope this answer will help you. Mark as brainliest.
Attachments:
Answered by DMani3
0
#include<iostream>
#include<conio.h>
using namespace std;
class prime
{
int a, k, i;
public:
prime(int x) {
a = x;
}
void calculate()
{
k = 1;
{
for (i = 2; i <= a / 2; i++) if (a % i == 0)
{
k = 0;
break;
}
else
{
k = 1;
}
}
}
void show()
{
if (k == 1)
cout << "\n" << a << " is Prime Number.";
else cout << "\n" << a << " is Not Prime Numbers.";
}
};
int main()
{
int a;
cout << "Enter the Number:"; cin>>a;
Class prime obj(a);
obj.calculate();
obj.show();
getch();
return 0;
}
Similar questions