View Code of Problem 19

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

Double click to view unformatted code.


Back to problem 19