Function to print all possible pairs
function print ( a , n ) { for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( i != j ) document . write ( a [ i ] + " " + a [ j ] + " " ) ; } } }