Product of all Subarrays of an Array | C ++ program to find product of all subarray of an array ; Function to find product of all subarrays ; Variable to store the product ; Compute the product while traversing for subarrays ; Printing product of all subarray ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void product_subarrays ( long long int arr [ ] , int n ) { long long int res = 1 ; for ( int i = 0 ; i < n ; i ++ ) { long long int product = 1 ; for ( int j = i ; j < n ; j ++ ) { product = product * arr [ j ] ; res *= product ; } } cout << res << " STRNEWLINE " ; } int main ( ) { long long int arr [ ] = { 10 , 3 , 7 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; product_subarrays ( arr , n ) ; return 0 ; }