View Code of Problem 19

#include <stdio.h>

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


	}

}

Double click to view unformatted code.


Back to problem 19