Product of absolute difference of every pair in given Array | C ++ program for the above approach ; Function to return the product of abs diff of all pairs ( x , y ) ; To store product ; Iterate all possible pairs ; Find the product ; Return product ; Driver Code ; Given array arr [ ] ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int getProduct ( int a [ ] , int n ) { int p = 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { p *= abs ( a [ i ] - a [ j ] ) ; } } return p ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << getProduct ( arr , N ) ; return 0 ; }