fork(3) download
  1. #include <stdio.h>
  2.  
  3.  
  4. int maxSubarrayProduct(int a[], int n)
  5. {
  6. int i,max=a[0],temp=1;
  7. for(i=0;i<n;i++){
  8. temp=temp*a[i];
  9. if(temp>max){
  10. max=temp;
  11. }
  12. if(temp==0){
  13. temp=1;
  14. }
  15.  
  16. }
  17. return max;
  18. }
  19.  
  20. // Driver Program to test above function
  21. int main()
  22. {
  23. int arr[] = {-2, -3, 0, -2, -40};
  24. int n = sizeof(arr)/sizeof(arr[0]);
  25. printf("Maximum Sub array product is %d", maxSubarrayProduct(arr, n));
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
Maximum Sub array product is 80