Max Element For which Array Sum is Zero

Given an array and you have to find max number  of element for which Array`s Element Sum equal to zero.
For example:-an array is a[] ={1,2,-2,6,-5,-1};array`s element 2,-2,6,-5,-1 sum is zero for maximum number of element in this array

#include<studio.h>
#include<stdlib.h> 

int max_Len(int a[],int n)
 { 
   int sum, i,j max_Len=0;

 for(i=0;i<n;i++)
  { 
  sum=0;
  { 
  for(j=i;j<n;j++)
   {
     sum=sum+a[j];
       if(sum==0) 
       max_Len=max(max_Len,j-i+1); 
  }
   }  
 return max_Len;
 } 

main()

int k, a[20],n; 
printf("enter array element:\n"); 

for(i=0;i<n;i++)
  { 
    scanf("%d",&a[i]);
  } 
    k=max_Len(a,n); 
    printf("Max element %d for which array sum is zero\n",k); 
}

Related Posts