View Code of Problem 19

#include <iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	while(n!=0){
		int a[n];
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		int max=a[0];
		int temp=0;
		for(int i=0;i<n;i++){
			temp+=a[i];
			if(temp>max) max=temp;
			if(temp<0) temp=0;
		}
		cout<<max<<endl;
		
		cin>>n;
	}
} 

Double click to view unformatted code.


Back to problem 19