Print all proper fractions with denominators less than equal to N | Java program to implement the above approach ; Function to print all proper fractions ; If the numerator and the denominator are coprime ; Driver code
class GFG { static 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 = String . valueOf ( i ) ; String b = String . valueOf ( j ) ; System . out . print ( a + " / " + b + " , ▁ " ) ; } } } } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int n = 3 ; printFractions ( n ) ; } }