Find N fractions that sum upto a given fraction N / D | Function to split the fraction into the N parts ; Loop to find the N - 1 fraction ; Loop to print the Fractions ; Driver Code ; Function Call
def splitFraction ( n , d ) : NEW_LINE INDENT ar = [ ] NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT ar . append ( 0 ) NEW_LINE DEDENT first = d + n - 1 NEW_LINE ar [ 0 ] = first NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT temp = first - 1 NEW_LINE ar [ i ] = first * temp NEW_LINE first -= 1 NEW_LINE DEDENT for i in range ( 0 , n ) : NEW_LINE INDENT if ar [ i ] % n == 0 : NEW_LINE INDENT print ( "1 / " , int ( ar [ i ] / n ) , " , " , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( n , " / " , ar [ i ] , " , " , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT N = 4 NEW_LINE D = 2 NEW_LINE splitFraction ( N , D ) NEW_LINE