View Code of Problem 19

#include <stdio.h>
int main()
{
	int n;
  	while(scanf("%d",&n)!=EOF&&n!=0)

        	int p[100];
          	for(int i=0;i<n;++i)
                  scanf("%d",&p[i]);
        
		int max=p[0];
          	for(int i=0;i<n;++i)
                {
                	int sum=0;
                  	for(int j=i;j<n;j++)
                        {
                          sum+=p[j];
                          if(sum>max)
                            max=sum;
                        }             
                }
                
      		printf("%d\n",max);
        }
}
/*
Main.c: In function 'main':
Main.c:7:10: error: expected expression before 'int'
          int p[100];
          ^
Main.c:9:31: error: 'p' undeclared (first use in this function)
                   scanf("%d",&p[i]);
                               ^
Main.c:9:31: note: each undeclared identifier is reported only once for each function it appears in
Main.c: At top level:
Main.c:25:1: error: expected identifier or '(' before '}' token
 }
 ^
*/

Double click to view unformatted code.


Back to problem 19