A fraction is a ratio of two values. Fractions have the form a/b where a is called the numerator, b is called the denominator and b cannot equal 0 (since division by 0 is undefined).The denominator gives how many equal parts are there. The numerator represents how many of these are taken. For example, one-half, eight-fifths, three-quarters (1/2, 8/5, 3/4).
Fact about Fraction :
- Fractions can be reduced if the numerator and denominator have a greatest common divisor(gcd) greater than 1.
- Addition and Subtraction of Fractions : When adding or subtracting fractions, they must have the same denominator. If they do not have the same denomimator, we must find a common one for both. To do this, we first need to find the lowest common multiple(lcm) of the two denominators or multiply each fraction by the proper integers so that there will be the same denominator.
- Multiplication and Division of Fractions : When multiplying two fractions, simply multiply the two numerators and multiply the two denominators.When dividing two fractions, the first fraction must be multiplied by the reciprocal of the second fraction.
- There are three types of fractions :
- Proper Fractions:The numerator is less than the denominator. For Example, 1/3, 3/4, 2/7
- Improper Fractions:The numerator is greater than (or equal to) the denominator. For Example, 4/3, 11/4, 7/7.
- Mixed Fractions: A whole number and proper fraction together. For Example, 1 1/3, 2 1/4, 16 2/5.
How to add two fraction ?
Add two fraction a/b and c/d and print answer in simplest form.
Input: 1/2 + 3/2 Output: 2/1 Input: 1/3 + 3/9 Output: 2/3 Input: 1/5 + 3/15 Output: 2/5
Algorithm to add two fractions
- Find a common denominator by finding the LCM (Least Common Multiple) of the two denominators.
- Change the fractions to have the same denominator and add both terms.
- Reduce the final fraction obtained into its simpler form by dividing both numerator and denominator by there largest common factor.
1/500 + 2/1500 is equal to 1/300
More problems related to Fraction:
- LCM and HCF of fractions
- Represent the fraction of two numbers in the string format
- Program to compare two fractions
- Convert Binary fraction to Decimal
- Convert decimal fraction to binary number
- Fractional Knapsack Problem
- Find Recurring Sequence in a Fraction
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.