Greatest Common Divisor

Source code of the program in GitHub.

This program basically asks the user for two numbers, and after that it calls for the function gcd to calculate the greatest common divisor of both numbers. 

The Greatest Common Divisor can be obtained very easly by contemplating three different escenarios, two of those are almost the same and are when one of the values is greater than the other, and the other is when the two are the same.

The goal of the function is to achieve that both numbers are the same so that the gcd is the same number. So we achieve this by using a simple if control form. Whenever a number is greater than the other we substract the smaller number from it and repeat the process until we have the same number.

This program is quite simple and you can try it so you better understand it.

This is my of my .

CC BY 4.0 Greatest Common Divisor by Manuel Lepe is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.