View Code of Problem 19

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {
	int n,a[1000],i,j;
	while(scanf("%d",&n)!=EOF){
	if(n==0){
		break;
	}
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	int max=a[0];
	for(i=0;i<n;i++){
		int 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