View Code of Problem 19

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,t,sum;
	while(scanf("%d",&n)!=EOF && n!=0){
		int num[n] = { };
		for(int i = 0;i<n;i++)cin>>num[i];
		int max = num[0];
		for(int i = 0;i<n;i++){
			sum = 0;
			for(int j = i;j<n;j++){
				sum = sum + num[j];
				if(sum > max) max = sum;
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 19