Q:

Ruby program to demonstrate the coerce() function

belongs to collection: Ruby Basic Programs

0

In this program, we will create two variables and initialize them with floating-point numbers. Then we will use coerce() function to combine two floating-point numbers and return an array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to demonstrate the coerce() function is given below. The given program is compiled and executed successfully.

# Ruby program to demonstrate 
# the coerce() function

num1 = 10.23;
num2 = 20.24;

arr = num1.coerce(num2);

print "Returned array: ",arr;

Output:

Returned array: [20.24, 10.23]

Explanation:

In the above program, we created two variables num1num2 and initialized 10.23, 20.24 respectively. Then we called coerce() library function to return the array of given floating-point numbers and printed the returned array.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Ruby Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Ruby program to demonstrate the arg() function... >>
<< Ruby program to get the denominator from a rationa...