ADVERTISEMENT
ADVERTISEMENT

Ruby program to demonstrate the arg() function

Ruby Example: Write a program to demonstrate the arg() function.
Submitted by Nidhi, on December 15, 2021

Problem Solution:

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

Program/Source Code:

The source code to demonstrate the arg() function is given below. The given program is compiled and executed successfully.

# Ruby program to demonstrate 
# the arg() function

num1 = 10;
num2 = -10;

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

Output:

0
3.141592653589793

Explanation:

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

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.