Menentukan Bilangan Prima

Analysis program:

Already know it primes?? A prime number (or a prime) is a natural number that has exactly two distinct natural number divisors1 and itself. For example, we input the number 3 it will be in the process with thisprogram that the results are excellent.

Algorithm:
1. Suppose this number is X.
2. number is even or odd.
3. If the numbers are completed (except 2) means not a prime number.
4. Numbers were only divisible by 1 and the number itself or not?
5. If not, then not a prime number.
6. If so, then the prime numbers.

Program :

#include <iostream.h>

class prima
{
 public:
  prima();
   input();
  proses();
 private:
  int bil, batas, x, i;
};

prima::prima()
{ cout<<"Menentukan bilangan prima atau bukan"<<endl<<endl;}
prima::input()
{ cout << "Masukkan bilangan : ";
 cin >> x;
 cout<<endl;}
prima::proses(){
 batas = 0;
 for ( i=1; i<=bil; i++)
 {
  if (bil%i==0 && x !=0)
  batas++; }

 if (batas==2){
 cout << "Termasuk bilangan prima \n"; }
 else                     {
 cout << "Bukan bilangan prima \n";}
}

int main()
{
prima bilangan;
bilangan.input();
bilangan.proses();

}
Iklan

Posted on April 22, 2011, in Alprog. Bookmark the permalink. Tinggalkan komentar.

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 )

w

Connecting to %s

%d blogger menyukai ini: