Ruby Integer gcd() function with example Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report 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: CPP # 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) Output: 5 7 Example #2: Ruby # Ruby program of Integer gcd() function # Initializing the numbers num1 = 22 num2 = 18 num3 = 30 num4 = 25 # Prints the gcd value puts num1.gcd(num2) puts num3.gcd(num4) Output: 2 5 Comment More infoAdvertise with us Next Article Ruby Integer gcd() function with example G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Integer-class Similar Reads Ruby Integer gcdlcm() function with example The gcdlcm() function in Ruby returns an array with the greatest common divisor and the least common multiple of the two integers. GCD signifies the greatest common divisor which divides both the numbers and lcm signifies the least common multiple of both the numbers Syntax: number1.gcdlcm(number2) 1 min read Ruby Integer div() function with example The div() function in Ruby returns the integer division of two numbers. Syntax: (number1).div(number2) Parameter: The function needs two numbers number1 and number2, where number1 is the dividend and number2 is the divisor. Return Value: The function returns the integer division of two numbers. Exam 1 min read Ruby Integer lcm() function with example The lcm() function in Ruby returns the lcm of two numbers. LCM signifies the lowest common multiple which is divisible by both the numbers. Syntax: number1.lcm(number2) Parameter: The function requires two numbers whose lcm is returned. Return Value: The function returns the lcm of two numbers Examp 1 min read Ruby Integer fdiv() function with example The fdiv() function in Ruby returns the floating point result after division of two numbers. Syntax: (number1).fdiv(number2) Parameter: The function needs two numbers number1 and number2, where number1 is the dividend and number2 is the divisor. Return Value: The function returns the floating point 1 min read Ruby Integer to_r function with example The to_r function in Ruby converts the value of the number to a rational. Syntax: number.to_r Parameter: The function takes the number which is to be converted to a rational number. Return Value: The function returns the rational number. Example #1: Ruby # Ruby program for to_r function # Initializi 1 min read Like