A simple program to add two fractions and display their sum in the simplest form is discussed here. Let us assume the fractions to be a/b and c/d. Now we need to add these and find out the resultant fraction.
Examples of Test cases:
Input: 1 2 3 2
Output: 2 1
Input: 1 3 3 9
Output: 2 3
Input: 1 5 3 15
Output: 2 5
1) Calculate the numerator and denominator of the resultant fraction (x/y).
2) Find the gcd of x and y.
3) Divide x and y by their gcd to get the resultant fraction in the simplest form.
@@coding::1@@
Complexity of adding two fractions: O(n)