Trusted answers to developer questions

NDUKWE CHIDERA K.

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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:

: First parameter.`num1`

: Second parameter.`num2`

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 $2^{53}$.

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))

**Line 1**: We include the`std/math.e`

file in the program code to use the method.**Lines 3 to 6**: The`gcd`

method returns the greatest common divisor of some integer value, and displays the result.

RELATED TAGS

gcd method

euphoria

maths

communitycreator

CONTRIBUTOR

NDUKWE CHIDERA K.

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Related Courses