Find all pairs ( a , b ) in an array such that a % b = k | method to find pair such that ( a % b = k ) ; Consider each and every pair ; Print if their modulo equals to k ; Driver Code
function printPairs ( arr , n , k ) { let isPairFound = true ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( i != j && arr [ i ] % arr [ j ] == k ) { document . write ( " " + arr [ i ] + " " + arr [ j ] + " " + " " ) ; isPairFound = true ; } } } return isPairFound ; } let arr = [ 2 , 3 , 5 , 4 , 7 ] ; let k = 3 ; if ( printPairs ( arr , arr . length , k ) == false ) document . write ( " " ) ;