View Code of Problem 19

#include<stdio.h>
int main(){
	int n;
	while(scanf("%d",&n)!=EOF&&n>=0){
		if(n==0) break;
		int a[n];
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		} //将所有数字存入数组
		//现在开始计算max
		int max;
		int sum;
		max=a[0];
		for(int i=0;i<n;i++){
			sum=0;
			for(int j=i;j<n;j++){
				sum+=a[j];
				if(sum>max){
					max=sum;
				}
			}
			
		} 
		
		printf("%d\n",max);
		
		}
	
	
	return 0;
} 

Double click to view unformatted code.


Back to problem 19