#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
bool Prima (int x){
int k, y;
bool test;
if (x<2){
return false;
}else if (x==2){
return true;
} else {
y = ceil(sqrt(x));
test = true;
}
while (test && (y>=2)){
if (x % y == 0){
test = false;
} else {
y = y-1;
}
}
return test;
}
int main(int argc, char *argv[])
{
int x;
cout<<"masukkan nilai:"<<endl;
cin>>x;
cout<<"Prima:"<<Prima(x)<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Tidak ada komentar:
Posting Komentar