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 thier 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:

This program will not run! First, choose num1, den1, and num2, den2 (the numerator and denominator of your two fractions). Try 8/21 and 5/6 to start (or num1=8, den1=21, num2=5, den2=6). Next, finish the cd= line to compute the common denominator using the discussion above. Dismiss.
Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.