judul

SELAMAT DATANG DAN SELAMAT MEMBACA BLOG KU :)

Selasa, 18 Maret 2014

The Greatest Common Divisor Of Two Integer



soal

masalah

   Di berikan 2 integer positif tidak atau bukan nol n & m, pola algoritma untuk mencari pembagi yang paling besar.

input dan output
                  M= integer (input)
                  N =integer
                  Gcd= integer (output)
                  R= integer
                  D= integer

algoritma

Read m,n
While (m <0) do
R ß n mod m
N ß m
End while
Gcd ß m
Write = (gcd)

test data

M= 36             n= 28
N= 28            m=8
R=36 % 28      gcd = 8
R= 8


jika diaplikasikan kedalam c++

Class gcd {
Friend ostream& operator << (ostream. Gcd&);
Friend istream& operator >> (istream. Gcd&);
Public;
Int hitung gcd (int ,int);
Private ;
Int x,y;
};
Int gcd :: hitung gcd (int ,(int d)
{ int r;
While ( d> 0);
R = c % d;
D= d;
D= r;
}
Return  ( r );
}
(istream& operation >> (istream& in, gcd& a){
Cout << “ inputkan bilangan petama ;” ;
In >> a.x;
Cout << “ inputkan bilangan kedua ; “ ;
In >> a.x;
Return in; }

Ostream& operation << istream& out , gcd& a){
Out << “gcd ‘ << a.c << “.” << a. x << );”;
Out << a.hitung gcd (a.x, a.y);
Return out;
}
Void main (){
Gcd run;
Cin >> run ;
Cout << run ;
Getch ();
}


semoga bermanfaat :))

Tidak ada komentar:

Posting Komentar