Given an array A [ ] and a number x , check for pair in A [ ] with sum as x | function to check for the given sum in the array ; checking for condition ; Driver Code
function printpairs ( arr , sum ) { let s = new Set ( ) ; for ( let i = 0 ; i < arr . length ; ++ i ) { let temp = sum - arr [ i ] ; if ( s . has ( temp ) ) { document . write ( " " + sum + " " + arr [ i ] + " " + temp + " " ) ; } s . add ( arr [ i ] ) ; } } let A = [ 1 , 4 , 45 , 6 , 10 , 8 ] ; let n = 16 ; printpairs ( A , n ) ;