#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
class Prima{
public:
bool prima(int x);
private:
int k, y;
bool test;
};
bool Prima::prima(int x){
if(x<2){
return false;
}
else
if (x==2){
return true;
}
else
y=ceil(sqrt(x));//pembulatan keatas
test=true;
while (test==true && y>=2){
if (x % y ==0)
test=false;
else
y=y-1;
}
return test;
}
int main(int argc, char *argv[]){
Prima uji;
int x;
cout<<"Masukan bilangan : ";
cin>>x;
uji.prima(x);
if(uji.prima(x)==0){
cout<<x<<" bukan bilangan prima"<<endl;
}
else
cout<<x<<" bilangan prima "<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
0 komentar:
Posting Komentar