View Code of Problem 19

#include <iostream>
using namespace std;

int main(){
    int n,sum,max;
    while(scanf("%d",&n)!=EOF&&n){
        int num[n];
        for (int i = 0; i<n; i++) {
            scanf("%d",&num[i]);
        }
        max = 0;
        for(int j = 0;j < n;j ++){
            sum = 0;
            for(int k = j;k < n;k ++){
                sum+=num[k];
                if(sum > max){
                    max = sum;
                }
            }
        }
        printf("%d\n",max);
    }
          return 0;
}

Double click to view unformatted code.


Back to problem 19