Possible pairs forming a Pythagorean Triple with a given value | Function to generate all possible pairs ; Vector to store all the possible pairs ; Checking all the possible pair in the range of [ 1 , c ) ; If the pair satisfies the condition push it in the vector ; Driver code ; If no valid pair exist ; Print all valid pairs
def Pairs ( C ) : NEW_LINE INDENT ans = [ ] NEW_LINE for i in range ( C ) : NEW_LINE INDENT for j in range ( i + 1 , C ) : NEW_LINE INDENT if ( ( i * i ) + ( j * j ) == ( C * C ) ) : NEW_LINE INDENT ans . append ( [ i , j ] ) NEW_LINE DEDENT DEDENT DEDENT return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT C = 13 ; NEW_LINE ans = Pairs ( C ) ; NEW_LINE if ( len ( ans ) == 0 ) : NEW_LINE INDENT print ( " No ▁ valid ▁ pair ▁ exist " ) NEW_LINE exit ( ) NEW_LINE DEDENT for i in range ( len ( ans ) ) : NEW_LINE INDENT print ( " ( " + str ( ans [ i ] [ 0 ] ) + " , ▁ " + str ( ans [ i ] [ 1 ] ) + " ) " ) NEW_LINE DEDENT DEDENT