View Code of Problem 19

#include <stdio.h>
#include <stdlib.h>
#include <math.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,i,j,sum;
	while(scanf("%d",&n)!=EOF){
		if(n==0){
			break;
		}
		int a[n];
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		int 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