给定个整数的序列,求函数的最大值。
#include<iostream>
using namespace std;
void MaxSubseqSum(int A[], int N)
{
int ThisSum=0, MaxSum=0;
for (int i = 0; i < N; i++)
{
ThisSum += A[i];
if (ThisSum > MaxSum)
{
MaxSum = ThisSum;
}
else if (ThisSum < 0)
{
ThisSum = 0;
}
}
cout<<"数组的最大子列和为:"<<MaxSum<<endl;
}
int main()
{
int number[] = { -1,3,-2,4,-6,1,6,-1 };
int len = sizeof(number) / sizeof(int);
//cout << "数组的长度为:" << len << endl;
MaxSubseqSum(number, len);
system("pause");
return 0;
}