usingMaths.com
From Theory to Practice - Math You Can Use.







<< Previous Next >>

How to Add Fractions using Perl | Step-by-Step Tutorial with Fun Exercises



Why Rationalise or Canonise Fractions before Addition | Maths Explanation for Perl Kids

In this Perl tutorial for junior secondary students, we explore how to add fractions. Before performing the addition, we rationalise or canonise the fractions to ensure accuracy. This method uses Finding LCM in Perl class to align denominators, making it ideal for math programming beginners.
This Perl tutorial teaches young students how to add fractions with different denominators.

Before fractions are added, they are rationalised; i.e., they are put in a form where their denominators become the same. This identical denominator is the LCM of the previous denominators of all the separate fractions.
After this is done, the new numerators can then be added together.



Step-by-Step Guide for Addition of Fractions - Perl Algorithm

The following steps will guide us in writing our Perl code for adding fractions.
Let's illustrate the steps to follow with the example fractional expression 2/5 + 7/4

Step 1:

Using the Find LCM in Perl class from the Primary Category, find the LCM of the denominators.
         ⇒ LCM of 5 & 4 = 20

Step 2:

In a turn by turn fashion, divide the found LCM from Step 1 by each denominator, multiplying the quotient by the corresponding numerator.
         ⇒ ((2 x 4) + (7 x 5))/20
         = (8 + 35)/20

Step 3:

Go ahead and add the numerators.
         ⇒ 43/20


Create a new Perl module file; Call it AddFraction.pm.;
Type out the adjoining Perl code for adding fractions.



Note: The code module for Learn how to find LCM in Perl is from the Primary Category.
Just make a copy of it into the current folder (project).

You can comment out the DivideFraction Perl object code in the main class from the previous lesson or simply continue from where it stopped.


So! Perl Fun Practice Exercise - Add Fractions

As a fun practice exercise, feel free to try out your own fractions with different numerators and denominators, and see how the Perl code adds these fractions.









<< Previous Next >>