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:
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.
Share your code
Show a friend, family member, or teacher what you've done!