Algoritma Menampilkan Bilangan Prima 1-100 C++

Program menampilkan bilangan prima antara 1 sampai 100 dengan C++.
Berikut Source Codenya :

#include “iostream.h”
#include “conio.h”
int main(){
int i,j,c;
cout<<“Bilangan Prima Antara 1-100 :\n\n”;
for(i=1;i<=100;i++){
c=0;
for(j=1;j<=i;j++){
if(i%j==0){c=c+1;}
}
if (c==2)cout<<i<<” “;
}
getch();
return 0;
}

 

Keluaran Program :

prima

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google

You are commenting using your Google account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s