Mencari KPK c++

Analysis Program:
This is a program to find the KPK or multiples of the smallest alliance between two numbers entered.
Here is the formula-rusmusnya sidah. First value = 0 because later will be added in search-and add the rest of the quotient between the two numbers that fed the fruit earlier.

Agoritma :

1. Inputkan 2 angka yang akan di cari KPKnya
2. nilai=0
3. for (int z=1; z<=masuk.b; z++)
4. masuk.nilai=masuk.nilai+masuk.a;
5. if (masuk.nilai%masuk.b==0)
6. Kembalikan nilai return
7. Hasil

#include <iostream.h>

#include <conio.h>

class kpk {

friend istream& operator>>(istream&, kpk&);

public :

kpk ();

private:

int a,b,nilai;

};

kpk::kpk() { cout<<"Menghitung KPK"<<endl; }

istream& operator>>(istream& in, kpk& masuk) {

masuk.nilai=0;

cout<<"Masukkan A: "; in>>masuk.a;

cout<<"Masukkan B: "; in>>masuk.b;

for (int z=1; z<=masuk.b; z++) {

masuk.nilai=masuk.nilai+masuk.a;

if (masuk.nilai%masuk.b==0) {

cout<<"KPK dari "<< masuk.a << " dan "<< masuk.b <<" adalah "<< masuk.nilai <<endl;

return in;

}

}

}

main () {

kpk X;

cin >> X;

getch ();

}

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: