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







<< Previous Next >>

Code for Adding Fractions in Visual Basic (VB.Net)



Rationalise (Canonise) the Fractions before Addition

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


Steps for Addition of Fractions VB.Net code

The following steps will guide us in writing our code.
Let's illustrate with 2/5 + 7/4

Step 1:

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 class file; Project, Add Class.
Call it AddFraction.vb.
Optionally, create a new module file; Project, Add Module.
Call it AddFractionModule.vb.
Type out the adjoining Visual Basic (VB.Net) codes for adding fractions.



Note: The code module for finding LCM is from the Primary Category.
Create a new Class File called LCM in your current project and copy the L.C.M. code into it.

You can instead comment out the previous VB.Net code from the main module or simply continue from where it stopped.


So!

Feel free to try out your own set of numerators and denominators for fractional addition.









<< Previous Next >>