ADVERTISEMENT
ADVERTISEMENT

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

Ruby Example: Write a program to check a number is zero or not using the zero?() function.
Submitted by Nidhi, on December 13, 2021

Problem Solution:

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?().

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.

Ruby Basic Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.