Q:

Ruby program to demonstrate the phase() function

belongs to collection: Ruby Basic Programs

0

In this program, we will create 2 variables and initialize them with some values. Then we will use the phase() function with created variables. The phase() function returns 0 if the variable contains a positive value otherwise it returns the value of "pi" which is 3.141592653589793.

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 phase() function is given below. The given program is compiled and executed successfully.

# Ruby program to demonstrate the 
# phase() function

num1 = 10;
num2 = -10;

print num1.phase(),"\n";
print num2.phase(),"\n";

Output:

0
3.141592653589793

Explanation:

In the above program, we created two variables num1num2, and initialized 10,-10 respectively. Then we used the phase() function with both variables to print the result. The phase() function returns 0, if value of variable is positive otherwise it returns value 3.141592653589793.

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 check a given number is finite or ... >>
<< Ruby program to demonstrate the <=> operator...