View Code of Problem 19

#include <stdio.h>
int main() {
    int n,i,max;
    
    while((scanf("%d",&n))!=EOF || n!=0){
        int a[100];
        int b[100];
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        b[0] = a[0];
        max = b[0];
        for(i=1;i<n;i++){
            if(b[i-1]>0)
                b[i] = b[i-1]+a[i];
            else
                b[i] = a[i];
            if(b[i]>max)
                max = b[i];
        }
        printf("%d\n",max);
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 19