February 2020
Beginner to intermediate
616 pages
15h 16m
English
Let's assume we want to find the GCD of two integers, 18 and 24. To do so, we will invoke the gcd(x,y) function, which in this case is gcd(18,24). Because 24, that is, y, is not zero, Rule 1 is not applicable here. Next, we will use Rule 2 to check whether 18%24 (x % y) is equal to 0. Because 18 cannot be divided by 24, 18 will be the remainder:

Since the parameters of Rule 2 were also not met, we will use Rule 3. We will invoke the gcd function with the gcd(b,m) argument, which is gcd(24,18%24). Now, m stands for the mod operation. At this stage, we will again apply Rule 2 and collect the remainder:
Read now
Unlock full access