Greatest common divisor · Pengangka persekutuan terbesar
Greatest common divisor
The GCD of two numbers is the largest integer that divides both. Euclid's algorithm is beautifully short: while b isn't 0, replace the pair (a, b) with (b, a % b). When b reaches 0, a is the answer.
Pembagi persekutuan terbesar
FPB dari dua bilangan adalah integer terbesar yang dapat membagi keduanya. Algoritma Euclid sangat ringkas: selama b tidak 0, ganti pasangan (a, b) dengan (b, a % b). Ketika b mencapai 0, a adalah jawabannya.
Complete int gcd(int a, int b) to return the greatest common divisor of a and b. Euclid's method: repeatedly replace (a, b) with (b, a % b) until b is 0. · Selesaikan int gcd(int a, int b) untuk mengembalikan pengangka persekutuan terbesar bagi a dan b. Kaedah Euclid: ganti (a, b) secara berulang dengan (b, a % b) sehingga b menjadi 0.
Click Run to see the output here. · Klik Jalankan untuk melihat output di sini.