View Code of Problem 19

#include<iostream>
#include<math.h>
using namespace std;
int main(){
	int n;
	while(cin>>n&&n>0){
		int a[n];
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		int temp=a[0],max=a[0];
		for(int i=0;i<n;i++){
			temp=0;
			for(int j=i;j<n;j++){
				temp=temp+a[j];
				if(max<temp)max=temp;
			}
		}
		cout<<max<<'\n';
	}
} 

Double click to view unformatted code.


Back to problem 19