Product of all non repeating Subarrays of an Array | C ++ program to find the product of all non - repeating Subarrays of an Array ; Function to find the product of all non - repeating Subarrays of an Array ; Finding the occurrence of every element ; Iterating through the array and finding the product ; We are taking the power of each element in array with the occurrence and then taking product of those . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; long product ( int arr [ ] , int n ) { double occurrence = pow ( 2 , n - 1 ) ; double product = 1 ; for ( int i = 0 ; i < n ; i ++ ) { product *= pow ( arr [ i ] , occurrence ) ; } return ( long ) product ; } int main ( ) { int arr [ ] = { 10 , 3 , 7 } ; int len = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << product ( arr , len ) ; return 0 ; }