View Code of Problem 19

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int n;
    while(cin>>n){
        if(n == 0)
            break;
    int a[999], sum = 0, max = 0;
    for(int i = 0; i < n; i++){
        cin>>a[i];
    }
        for(int i = 0; i < n; i++){
            sum = 0;
            for(int j = i; j < n; j++){
                sum += a[j];
                if(sum > max)
                    max = sum;
            }
        }
        cout<<max<<endl;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 19