#include <conio.h>
class yayan
{
public:
int a, i;
yayan();
void prima(void);
};
yayan :: yayan(void)
{
cout << "Masukkan bilangan bulat positif : ";
cin >> a;
prima();
}
void yayan :: prima(void)
{
char zero[] = "tidak boleh zero";
char neg[] = "tidak boleh negatif";
char notprime[] = "bukan bilangan prima";
char prime[] = "bilangan prima";
try
{
if (a == 0) throw zero;
if (a < 0) throw neg;
for (int i = 3; i <= sqrt (a); i++)
{
if ((a/i) * i == a) throw notprime;
}
throw prime;
}
catch (char *conclusion)
{
cout << "angka yang dimasukkan adalah "<< conclusion << endl;
}
cout << endl;
}
void main(void)
{
clrscr();
yayan r1;
getch();
}
No comments:
Post a Comment