next up previous
Next: GCD: by directly exploiting Up: Unit 06 Previous: Complete set of control

Example: computing the greatest common divisor (GCD)

Specification:

We want to realize a static public method that takes as parameters two positive integers x and y and computes and returns their greatest common divisor gcd(x, y).

The greatest common divisor of two integers x and y is the greatest integer that divides both x and y without rest.

Example:
gcd(12, 8) = 4
gcd(12, 6) = 6
gcd(12, 7) = 1


next up previous
Next: GCD: by directly exploiting Up: Unit 06 Previous: Complete set of control