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.
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.
Output:
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