Given two integers x and y and where x is divisible by y. It can be represented in the form of a fraction x/y. The task is to reduce the fraction to its lowest form.
Input : x = 16, y = 10 Output : x = 8, y = 5 Input : x = 10, y = 8 Output : x = 5, y = 4
Approach: Both of the values x and y will be divisible by their greatest common divisor. So if we divide x and y from the gcd(x, y) then x and y can be reduced to its simplest form.
Below is the implementation of the above approach:
x = 8, y = 5
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Find ΔX which is added to numerator and denominator both of fraction (a/b) to convert it to another fraction (c/d)
- First occurrence of a digit in a given fraction
- Greedy Algorithm for Egyptian Fraction
- Find Recurring Sequence in a Fraction
- Find N fractions that sum upto a given fraction N/D
- Convert Binary fraction to Decimal
- Expressing a fraction as a natural number under modulo 'm'
- Maximum rational number (or fraction) from an array
- Represent the fraction of two numbers in the string format
- Find the Nth digit in the proper fraction of two numbers
- Largest proper fraction with sum of numerator and denominator equal to a given number
- Build Lowest Number by Removing n digits from a given number
- Reduce N to 1 with minimum number of given operations
- Reduce a number to 1 by performing given operations | Set 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.