The greatest common divisor and the common multiple
No. 107
Finding the greatest common divisor of two integer values
Q: |
We recall the section called “Example: A class representing fractions”. So far no one
demanded cancelling fractions. Yet calling Cancelling fractions requires implementing e.g. the Euclidean algorithm in order to find the greatest common divisor (GCD) of two non-zero integer values. Read the above link and implement a class method
getGcd(long, long) inside a class
With respect to fractions one or both parameters
Based on TipFollow the test driven approach: Provide dummy methods
and write tests prior to implementation of
|
A: |
Implementing
Knowing the the gcd of two values a and b the common multiple may be obtained by . Thus we have:
|