Program C++ Menentukan Bilangan Prima
#include<iostream>
using namespace std;
main()
{
int a,i,count=0;
cout<<"\n Masukkan
Angka : ";
cin>>a;
for(i=2;i<=a/2;i++)
{
if(a%i==0)
count++;
}
cout<<"\n";
if(count>0 || a<2)
cout<<"
"<<a<<" ('bukan bilangan prima')\n";
else
cout<<"
"<<a<<" ('bilangan prima')\n";
}
|
Pseudocode Menentukan Bilangan Prima
Algoritma: menentukan bilangan prima
Deklarasi:
a, i, count=0 : integer
1. read
(input)
2. count
:= 0
3. for
(i=1 to input) do begin
4. if
(input mod i ==0) then begin
5. count++
6. end
7. end
for
8. if
(count==2) then write ("Bilangan prima")
9. else
write ("Bukan prima")
|
Tidak ada komentar:
Posting Komentar