View Code of Problem 19

#include <stdio.h>
#include <stdlib.h>

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

Double click to view unformatted code.


Back to problem 19