View Code of Problem 19

# include<stdio.h>
int main(void)
{
  int i,t,j,max,sum;
  int a[100] = {0};
  while (scanf("%d",&t))
  {
	  if(t==0)
	  break;
      for(j=0;j<t;++j)
		{
		  scanf("%d",&a[j]);
		}
   	  max = a[0];
	  for(j=0;j<t;++j)
		{
		  sum = 0;
		  for(i=j;i<t;++i)
		  {
			sum = sum + a[i];
			if(sum>max)
			{
			  max = sum;
			}
		  }
		}
  }
  printf("%d",max);
  return 0;
}

Double click to view unformatted code.


Back to problem 19