Sum of all ordered pair | C ++ program to implement the above approach ; Function to calculate the sum of all pair - products ; Stores sum of array ; Update sum of the array ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int sumOfProd ( int arr [ ] , int N ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } return sum * sum ; } int main ( ) { int arr [ ] = { 2 , 3 , 1 , 5 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << sumOfProd ( arr , N ) ; return 0 ; }