Related Tags

gcd method
euphoria
maths
communitycreator

What is gcd() method in Euphoria?

NDUKWE CHIDERA K.

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.

Overview

The gcd() math method is part of Euphoria’s standard math library package. We can use it to compute the greatest common divisorgcd of two numbers.

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 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}$.

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