求一个用C语言写的最大子序列和代码
1个回答
展开全部
int FindGreatestSumOfSubArray(int *pData, int nLength)
{
int index;
int sum = 0;
int mostsum = 0;
for( index = 0; index < nLength; ++index )
{
sum += pData[index];
if( sum > mostsum )
mostsum = sum;
if( sum < 0 )
sum = 0;
}
return mostsum;
}
{
int index;
int sum = 0;
int mostsum = 0;
for( index = 0; index < nLength; ++index )
{
sum += pData[index];
if( sum > mostsum )
mostsum = sum;
if( sum < 0 )
sum = 0;
}
return mostsum;
}
追问
编译无错,执行有2个错,怎么破
追答
结果错误?你的测试用例是?输出结果是?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询