usingMaths.com
Demonstrating and showing pupils and students one application of Mathematics.







<< Previous Next >>

Code for Converting a Mixed Fraction to Improper Fraction in Perl



Fractional Numbers

Like we all know, fractional numbers can either be Proper (e.g. 2/5), Improper (e.g. 5/2), or Mixed (e.g. 21/2),



Mixed to Improper Fraction Code in Perl

Say we have the fraction 32/5 - which is a mixed fraction; we can convert this fraction to an improper fraction by following a number of steps:

Step 1:

Multiply the whole number (3), by the denominator (5)
         ⇒ 3 X 5 = 15

Step 2:

Add the result from Step 1 to the numerator (2)
         ⇒ 15 + 2 = 17

Step 3:

Our obtained improper fraction is our new numerator (17) divided by our denominator (5).

Create a new Perl Class File; call it Algebra.pl.
Create a new Perl Module File; call it MixedToImproper.pm.

Type out the adjoining Perl code for converting mixed to improper fraction.


So!

Feel free to try out your own whole number, numerator and denominator.









<< Previous Next >>