#include <stdio.h>
int maxSubarrayProduct(int a[], int n)
{
int i,max=a[0],temp=1;
for(i=0;i<n;i++){
temp=temp*a[i];
if(temp>max){
max=temp;
}
if(temp==0){
temp=1;
}
}
return max;
}
// Driver Program to test above function
int main()
{
int arr[] = {-2, -3, 0, -2, -40};
int n = sizeof(arr)/sizeof(arr[0]);
printf("Maximum Sub array product is %d", maxSubarrayProduct
(arr
, n
)); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiAKCmludCBtYXhTdWJhcnJheVByb2R1Y3QoaW50IGFbXSwgaW50IG4pCnsKICAgaW50IGksbWF4PWFbMF0sdGVtcD0xOwogICBmb3IoaT0wO2k8bjtpKyspewogICAJdGVtcD10ZW1wKmFbaV07CiAgIAlpZih0ZW1wPm1heCl7CiAgIAkJbWF4PXRlbXA7CiAgIAl9CiAgIAlpZih0ZW1wPT0wKXsKICAgCQl0ZW1wPTE7CiAgIAl9CiAgIAkKICAgfQogICByZXR1cm4gbWF4Owp9CiAKLy8gRHJpdmVyIFByb2dyYW0gdG8gdGVzdCBhYm92ZSBmdW5jdGlvbgppbnQgbWFpbigpCnsKICAgIGludCBhcnJbXSA9IHstMiwgLTMsIDAsIC0yLCAtNDB9OwogICAgaW50IG4gPSBzaXplb2YoYXJyKS9zaXplb2YoYXJyWzBdKTsKICAgIHByaW50ZigiTWF4aW11bSBTdWIgYXJyYXkgcHJvZHVjdCBpcyAlZCIsIG1heFN1YmFycmF5UHJvZHVjdChhcnIsIG4pKTsKICAgIHJldHVybiAwOwp9Cg==