Menentukan FPB

Algoritma :
1.) Diasumsikan terdapat tiga buah variabel a,b, dan c.
2.) a dan b bernilai suatu angka yang ingin dicari fpbnya
(b bukan 0)
c = a % b
a = b
b = c
3.) hasil

Program :

#include 
#include 

  class fpb{
  public:
  fpb();
  input();
  hitung();

  private:
  hasil();
  int a,b,c;
  };

  fpb::fpb(){
  cout<<"menentukan fpb\n";}
  fpb::input(){
  cout<>a;
  cout<>b;}
  fpb::hitung(){

    while(b>0){ c=a%b; a=b; b=c; }
    cout<<"FPB : "<<a;
    cout<<endl;}

 main()
  fpb x;
  x.input();
  x.hitung();
 }

Posted on April 14, 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 )

Connecting to %s

%d blogger menyukai ini: