Tuesday, 1 April 2014

praktikum strategi algoritma 2 tentang bilangan prima



#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;
}

No comments:

Post a Comment

Konversi Suhu

#include <iostream> #include <conio.h> //#include <cstdlib> //#include <iostream.h> void main( float Celcius, Kelvi...