In this assignment I had to write a function to calculate the greatest common denominator of two positive integers given by the user using Euclid’s algorithm.

I made 3 different versions of the function. On the first one I used iteration, on the second I used a loop based on the successive remainders and the stopping condition of 0 according to the algorithm, and on the last one I use a loop and conditional to do repeated subtraction, supposing that the input consists of positive integers and stops when the resulting numbers are equal.

You can find the source code HERE

CC BY 4.0 WSQ12 – Greatest Common Divisor by carminaperezguerrero is licensed under a Creative Commons Attribution 4.0 International License.