The gcd()
math method is part of Euphoria’s standard math library package. We can use it to compute the
This gcd()
math method evaluates the largest number that can divide values without any remainder. If the gcd
of the two values supplied have a fractional part, the first number after the decimal point should be a zero.
gcd(num1, num2)
Below is a simple explanation of the parameters:
num1
: First parameter.num2
: Second parameter.The order of the input parameters does not change the output.
The gcd
function returns an integer value, the largest value that can divide both integers provided with no remainder value.
Note:
- It uses absolute values of both parameters.
- Float numbers round down to integers.
- It returns zero if both parameters are zero.
- If one parameter happens to be zero, it returns the other non-zero parameter as the
gcd
value.- We cannot have a sequence as a parameter. It has to be an atom, and the maximum value can be up to .
Let’s look at the code below:
include std/math.eprintf(1,"The gcd of 4 and 64 is: %d", gcd(4,64))printf(1,"\nThe gcd of 100 and 1024 is: %d", gcd(100,1024))printf(1, "\nThe gcd of 0 and 0 is: %d", gcd(0,0))printf(1, "\nThe gcd of 0 and 20 is: %d", gcd(0,20))
std/math.e
file in the program code to use the method.gcd
method returns the greatest common divisor of some integer value, and displays the result.