标签:max can 数组元素 turn return print printf stdio.h ++
#include <stdio.h>
int main()
{
int A[20], i, n, max = 0 , sum = 0;
printf("请输入数组元素个数:\n");
scanf_s("%d", &n);
printf("请依次输入数组元素,中间用空格隔开:\n");
for (i = 0; i < n; i++)
scanf_s("%d", &A[i]);
for (i = 0; i < n; i++)
{
sum += A[i];
if (sum>=max)
max = sum;
else
sum = 0;
}
printf("最大子数组的和:%d\n", max);
return 0;
}
标签:max can 数组元素 turn return print printf stdio.h ++
原文地址:https://www.cnblogs.com/jiemoshaobing/p/9769880.html