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 Program ; If no valid pair exist ; Print all valid pairs
function Pairs ( C ) { var ans = [ ] ; for ( var i = 1 ; i < C ; i ++ ) { for ( var j = i + 1 ; j < C ; j ++ ) { if ( ( i * i ) + ( j * j ) == ( C * C ) ) { ans . push ( [ i , j ] ) ; } } } return ans ; } var C = 13 ; var ans = Pairs ( C ) ; if ( ans . length == 0 ) { document . write ( " " ) ; } ans . forEach ( x => { document . write ( " " + x [ 0 ] + " " + x [ 1 ] + " " + " " ) ; } ) ;