ADVERTISEMENT
ADVERTISEMENT

Ruby program to calculate the value from the given fraction and exponent

Ruby Example: Write a program to calculate the value from the given fraction and exponent.
Submitted by Nidhi, on December 07, 2021

Problem Solution:

In this program, we will read the fraction and exponent from the user. Then we will get the value of fraction and exponent using Math.idexp() function.

Program/Source Code:

The source code to find the value of fraction and exponent is given below. The given program is compiled and executed successfully.

# Ruby program to find the 
# value of fraction and exponent

print "Enter fraction: ";
fraction = gets.chomp.to_f;  

print "Enter exponent: ";
exponent = gets.chomp.to_i;  

value = Math.ldexp(fraction, exponent);
print "Value: ",value;

Output:

Enter fraction: 0.890625
Enter exponent: 9
Value: 456.0

Explanation:

In the above program, we read fraction and exponent from the user and found the value of fraction and exponent using the Math.idexp() 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.