Print all proper fractions with denominators less than equal to N | C ++ program to implement the above approach ; Function to print all proper fractions ; If the numerator and the denominator are coprime ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printFractions ( int n ) { for ( int i = 1 ; i < n ; i ++ ) { for ( int j = i + 1 ; j <= n ; j ++ ) { if ( __gcd ( i , j ) == 1 ) { string a = to_string ( i ) ; string b = to_string ( j ) ; cout << a + " / " + b << " , ▁ " ; } } } } int main ( ) { int n = 3 ; printFractions ( n ) ; return 0 ; }