# Khan/khan-exercises

### Subversion checkout URL

You can clone with HTTPS or Subversion.

Fetching contributors…

Cannot retrieve contributors at this time

51 lines (48 sloc) 2.276 kb
randRangeNonZero( -9, 9 ) randRangeNonZero( -9, 9 ) randRangeExclude( 2, 9, [ N1, -N1 ] ) randRangeExclude( 2, 9, [ N2, -N2 ] ) getLCM( D1, D2 ) LCM / D1 LCM / D2

fraction( N1, D1 ) + fraction( N2, D2 ) = {?}

N1 / D1 + N2 / D2

First, we need to find a common denominator. The least common multiple of D1 and D2 is the smallest possible common denominator.

\lcm(D1, D2) = LCM

Now, we need to change both fractions to have a denominator of LCM.

\begin{align*}fraction( N1, D1 )\cdot fraction( F1, F1 ) &= fraction( N1 * F1, LCM )\\ fraction( N2, D2 )\cdot fraction( F2, F2 ) &= fraction( N2 * F2, LCM )\end{align*}

So, the problem becomes:

fraction( N1 * F1, LCM ) + fraction( N2 * F2, LCM ) = {?}

N2 > 0 ? "Add" : "Subtract" the numerators.

fraction( F1 * N1 + F2 * N2, LCM)

Simplify.

fractionReduce( F1 * N1 + F2 * N2, LCM )

Something went wrong with that request. Please try again.