Lesson goal: Fraction adder and reducer using GCF and LCM

Previous: Finding common denominators using the LCM | Home | Next: Is a number prime?

Ok, so if you followed along in the last several lessons with the GCD and LCM, and their roles in reducing and adding fractions, we are set to build a full-out fraction adder, that will reduce the answer to lowest terms.

Before we proceed, you have to think carefully about the process of adding two fractions. First you find the common denominator, right? In the code below, we'll hold that in the variable cd. What do you do with the common denominator? You see by what factor (call it $f$) you have to multiply the denominator of a fraction by to get the common denominator. You then multiply the top and bottom of the given fraction by this $f$ (or multiple by "1" which is $\frac{f}{f}$. This becomes the new fraction with the common denominator in place.

Next, you repeat this procedure for the other fraction. When done, you should have two fractions with a common denominator.

The two fractions are added together by adding their two numerators and keeping the common denominator. This is the answer, which needs to be reduced to lowest terms (by dividing the numerator and denominator by their GCD). Sounds simple, right?

Now you try. Running the program and adding some fractions together.

Type your code here:

See your results here: