View Code of Problem 19

#include <stdio.h>
main(){
	int a[10000] = {0}; 
	int i = 0,n,sum,max;
	while(scanf("%d",&n)){
		if(n == 0)
			break;
		sum = 0;
		max = -10000;
		for(i = 0; i<n; i++)
			scanf("%d",&a[i]);
		for(i = 0; i<n; i++){
			if(sum > 0)
				sum+= a[i];
			else
				sum = a[i];
			if( max < sum )
				max = sum;
		}
		printf("%d\n",max);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 19