Given an integer N, the task is to print all proper fractions such that the denominator is less than or equal to N.
Proper Fractions: A fraction is said to be a proper fraction if the numerator is less than the denominator.
Input: N = 3
Output: 1/2, 1/3, 2/3
Input: N = 4
Output: 1/2, 1/3, 1/4, 2/3, 3/4
Traverse all numerators over [1, N-1] and, for each of them, traverse over all denominators in the range [numerator+1, N] and check if the numerator and denominator are coprime or not. If found to be coprime, then print the fraction.
Below is the implementation of the above approach:
1/2, 1/3, 2/3,
Time Complexity: O(N2)
Auxiliary Space: O(1)
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.
- Print all prime numbers less than or equal to N
- Print all Semi-Prime Numbers less than or equal to N
- Print all Strong numbers less than or equal to N
- Highest and Smallest power of K less than and greater than equal to N respectively
- Largest proper fraction with sum of numerator and denominator equal to a given number
- Find all factorial numbers less than or equal to n
- Find all powers of 2 less than or equal to a given number
- Find all possible subarrays having product less than or equal to K
- Sum of all proper divisors of a natural number
- Sum of all proper divisors of natural numbers in an array
- Sum of product of proper divisors of all Numbers lying in range [L, R]
- Sum of all proper divisors from 1 to N
- Print a number strictly less than a given number such that all its digits are distinct.
- Print all Prime Quadruplet of a number less than it
- Print all numbers less than N with at-most 2 unique digits
- Program to add two fractions
- Program to compare two fractions
- HCF of array of fractions (or rational numbers)
- Product of given N fractions in reduced form
- LCM and HCF of fractions
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.