Jumat, 02 Maret 2012

Fungsi Program Mencari bilangan Prima

#include <iostream.h>

int main()
{
int a, b, i;

cout << "===================================  "<<endl;
cout << "---Program Menentukan Bil. Prima---  "<<endl;
cout << "===================================\n"<<endl;
cout << "Masukkan bilangan bulat positif : ";cin >> a;
b = 0;
for (i=1; i<=a; i++)
if (a%i==0)
b++;

if (b==2)
cout <<a<< " adalah bilangan prima ";
else
cout <<a<< " bukan bilangan prima ";

return 0;
}

Tidak ada komentar:

Posting Komentar