#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main() { int i,j,n,a[n],max,sum; while(scanf("%d",&n)!=EOF) { if(n==0) { break; } for(i=0;i<n;i++) { scanf("%d",&a[i]); } max=a[0]; for(i=0;i<n;i++) { sum=0; for(j=i;j<n;j++) { sum=sum+a[j]; if(sum>max) { max=sum; } } } printf("%d\n",max); } return 0; } |
Double click to view unformatted code.