View Code of Problem 19

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

Double click to view unformatted code.


Back to problem 19