View Code of Problem 19

#include <stdio.h>
int main()
{
	int i,j,n;
  	while (scanf("%d",&n)!=EOF&&n!=0)
        {
          	int a[100];
        	for(i=0;i<n;++i)
                  scanf("%d",&a[i]);
          
          	int max=0;
          	for(i=0;i<n;++i)
                  int sum=0;
                  for(j=i;j<n;++j)
                  {
                  	sum+=a[j];
                    	if(max<sum)
                          max=sum;
                  
                  
                  }
        
        
        	printf("%d\n",max);
        
        
        }
 
 
 
 
}
/*
Main.c: In function 'main':
Main.c:14:19: error: expected expression before 'int'
                   int sum=0;
                   ^
Main.c:17:20: error: 'sum' undeclared (first use in this function)
                    sum+=a[j];
                    ^
Main.c:17:20: note: each undeclared identifier is reported only once for each function it appears in
*/

Double click to view unformatted code.


Back to problem 19