Q:

Ruby program to check a number is zero or not using the zero?() function

belongs to collection: Ruby Basic Programs

0

In this program, we will create 3 variables with some initial value. Then we will check given number is zero or not using library function zero?().

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 check a number is zero or not using zero?() the function is given below. The given program is compiled and executed successfully.

# Ruby program to check a number 
# is zero or not using the zero?() 
# function

num1 = 0;  
num2 = Complex(0,0);  
num3 = Complex(2,0);  

print "Num1: "  ,num1.zero?();
print "\nNum2: ",num2.zero?();
print "\nNum3: ",num3.zero?();

Output:

Num1: true
Num2: true
Num3: false

Explanation:

In the above program, we created three numbers with some initial values and checked the created variable contains value zero or not using zero?() function. The zero?() function returns Boolean values true or false based on the value of the variable is zero or not. After that, we printed the result.

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 inspect() function... >>
<< Ruby program to perform float division of two numb...