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
def printPairs ( arr , arr_size , sum ) : NEW_LINE INDENT s = set ( ) NEW_LINE for i in range ( 0 , arr_size ) : NEW_LINE INDENT temp = sum - arr [ i ] NEW_LINE if ( temp in s ) : NEW_LINE INDENT print " Pair ▁ with ▁ given ▁ sum ▁ " + str ( sum ) + NEW_LINE DEDENT DEDENT " ▁ is ▁ ( " + str ( arr [ i ] ) + " , ▁ " + str ( temp ) + " ) " NEW_LINE INDENT s . add ( arr [ i ] ) NEW_LINE DEDENT DEDENT A = [ 1 , 4 , 45 , 6 , 10 , 8 ] NEW_LINE n = 16 NEW_LINE printPairs ( A , len ( A ) , n ) NEW_LINE