View Code of Problem 19

#include<stdio.h>
int main(){
	int n,i,j;
	while(scanf("%d",&n)!=EOF){
		if(n==0)
		break;
		int a[n];
		for(i=0;i<n;i++)
		scanf("%d",&a[i]);
		int max=a[0];
		int s=0;
		for(i=0;i<n;i++){
			s=0;
			for(j=i;j<n;j++)
			{
				s+=a[j];
				if(s>max)
				max=s;
			}
		}
		printf("%d\n",max);
	}
}

Double click to view unformatted code.


Back to problem 19