View Code of Problem 19

#include<stdio.h>

int main() {
	while (1) {
		int n, i, j;
		scanf("%d", &n);
		if (n == 0)
			break;
		int a[10000], max = 0;
		for (i = 0; i < n; i++) {
			scanf("%d", &a[i]);
			max += a[i];
		}
		for (int i = 0; i < n; i++)
		{
			int sum = 0;
			for (int j = i; j < n; j++)
			{
				sum += a[j];
				if (sum>max)
				{
					max=sum;
				}
			}
		}
		printf("%d\n", max);
	}
}

Double click to view unformatted code.


Back to problem 19