ADVERTISEMENT
ADVERTISEMENT

Ruby program to get the predecessor of an integer number using library function

Ruby Example: Write a program to get the predecessor of an integer number using library function.
Submitted by Nidhi, on December 14, 2021

Problem Solution:

In this program, we will create two variables and initialize them with some values. Then we will get the predecessor of a given number using the pred() library function.

Program/Source Code:

The source code to get the predecessor of an integer number using the library function is given below. The given program is compiled and executed successfully.

# Ruby program to get the predecessor of an 
# integer number using library function

num1 = 20;
num2 = -23

print "Predecessor of num1: ",num1.pred(),"\n";
print "Predecessor of num2: ",num2.pred(),"\n";

Output:

Predecessor of num1: 19
Predecessor of num2: -24

Explanation:

In the above program, we created two variables num1, num2 and initialized 20, -23 respectively. Then we got the predecessor of the given integer number using the pred() library function and 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.