-->
当前位置:首页 > 题库 > 正文内容

填空题:写出以下程序段的运行结果。请注意,直接填数字,前后不要加空格等任何其他字符。

Luz3年前 (2022-06-12)题库1110
写出以下程序段的运行结果。请注意,直接填数字,前后不要加空格等任何其他字符。
{C}
int i, max_sum, n, this_sum;
int a[ ] = {-1, 3, -2, 4, -6, 1, 6, -1};
scanf("%d", &n);
max_sum = this_sum = 0;
for( i = 0; i < n; i++ ) {
this_sum += a[i];
if( this_sum > max_sum ) max_sum = this_sum;
else if( this_sum < 0 ) this_sum = 0;
}
printf("%d\n", max_sum);

输入8,输出

输入5,输出






答案:
第1空:7 ||

第2空:5 ||

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。