What is gcd() method in Euphoria?
Overview
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.
Syntax
gcd(num1, num2)
Parameters
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.
Return value
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
gcdvalue.- We cannot have a sequence as a parameter. It has to be an atom, and the maximum value can be up to .
Example
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))
Explanation
- Line 1: We include the
std/math.efile in the program code to use the method. - Lines 3 to 6: The
gcdmethod returns the greatest common divisor of some integer value, and displays the result.