Mengecek Bilangan Prima

Source Code C++ untuk mengecek apakah suatu bilangan merupakan bilangan prima atau bukan.

#include <conio.h>
/*
tested in Turbo C++ 4.5
*/
#include <iostream.h>

main(){
	int prima;
	int i, bil = 0;

	Ulang:
	prima = 1; // prima di set true
	cout << "Masukkan bil : ";
	cin >> bil;

	for(i=2;i<bil;i++){
		if(bil%i==0){
			prima = 0;
		}
	}
	if(bil<2){
		prima = 0;
	}
	if(prima==0){
		cout << "Bukan Bilangan Prima !!";
	}else{
		cout << "Bilangan Prima !!";
	}

	getche();
   clrscr();
	goto Ulang;

}

selamat mencoba.. :mrgreen:


7 Responses to “Mengecek Bilangan Prima”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.