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.
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 num1, num2 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.
Program/Source Code:
The source code to demonstrate the coerce() function is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created two variables num1, num2 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