View Code of Problem 19

#include<stdio.h>
#include<stdlib.h>

int num[10000];
int main(){
	int n;
	while((scanf("%d",&n)!=EOF) && n!=0){
		for(int i=0; i<n; i++)
			scanf("%d",&num[i]);

		long long int max = -9999999;
		for(int i=0; i<n; i++){
			long long int sum = 0;
			for(int k=i; k<n; k++){
				sum += num[k];
				if(sum>max)
					max = sum;
			}
				
		}
		printf("%lld\n",max);
	
	}

	return 0;

}

Double click to view unformatted code.


Back to problem 19