hitung prima 1-500 ..

#include<iostream.h>

#include<conio.h>

using namespace std;

int main()

{

char tanya;

int bilangan,jumlah,prima;

do

{

system(“cls”);

cout<<” | =============================== |”<<endl;

cout<<” | Program Penghitung Bilangan Prima [ 1..500 ] |”<<endl;

cout<<” |================================ |”<<endl<<endl;

cout<<“ Masukkan Bilangan : “;

cin>>bilangan;

cout<<endl;

cout<<“ Faktor – Faktor Bilangan : ” ;

cout<<endl;

while(bilangan<1 || bilangan>500);

for(int i=1;i<=bilangan;i++)

{

prima=1;

for(int j=2;j<i;j++)

{

if(i%j==0) prima–;

}

if (prima==1)

{

printf(“ %d “, i);

}

}

cout<<endl;

cout<<endl;

cout<<“ Ingin Hitung Kembali (y/t)?”;

cin>>tanya;

} while(tanya==’y’);

return 0;

}

bilprima

This entry was posted in Struktur Control and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *