Ruby Integer gcd() function with example
The gcd() function in Ruby returns the gcd of two numbers. GCD signifies the greatest common divisor which divides both the numbers.
Syntax: number1.gcd(number2)
Parameter: The function requires two numbers whose gcd is to be returned.
Return Value: The function returns the gcd of two numbers
Example #1:
# Ruby program of Integer gcd() function # Initializing the numbers num1 = 10 num2 = 15 num3 = 21 num4 = 14 # Prints the gcd value puts num1.gcd(num2) puts num3.gcd(num4) |
chevron_right
filter_none
Output:
5 7
Example #2:
# Ruby program of Integer gcd() function # Initializing the numbers num1 = 22num2 = 18num3 = 30num4 = 25 # Prints the gcd value puts num1.gcd(num2) puts num3.gcd(num4) |
chevron_right
filter_none
Output:
2 5
Recommended Posts:
- Ruby Integer integer? function with example
- Ruby Integer lcm() function with example
- Ruby Integer div() function with example
- Ruby Integer odd? function with example
- Ruby Integer even? function with example
- Ruby Integer next function with example
- Ruby Integer abs() function with example
- Ruby | Integer << function
- Ruby Integer chr function with example
- Ruby | Integer >= function
- Ruby | Integer <=> function
- Ruby | Integer - function
- Ruby Integer bit_length function with example
- Ruby Integer pred() function with example
- Ruby Integer to_d() function with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


