![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
求最大子列和问题 undefined reference to `MaxSubseqSum(int, int)'
#include<stdio.h>intMaxSubseqSum(int,int);intmain(){intm,N;scanf("%d\n",&N);inta[N];i...
#include<stdio.h>int MaxSubseqSum(int ,int);int main(){ int m,N; scanf("%d\n",&N); int a[N]; if(m < N) scanf("%d ",a[N++]); printf("%d",MaxSubseqSum(a[N] ,N)); return 0; } int MaxSubseqSum(int A[] ,int N) { int ThisSum ,MaxSum; int i; ThisSum = MaxSum = 0; for(i = 0;i < N;i++) { ThisSum += A[i]; if(ThisSum > MaxSum) MaxSum = ThisSum; if(ThisSum < 0) ThisSum = 0; } return MaxSum; }
展开
1个回答
展开全部
#include<stdio.h>
int MaxSubseqSum(int[] ,int);
int main()
{ int m,N;
scanf("%d\n",&N);
int a[N];
for(m=0;m<N;)
scanf("%d",&a[m++]);
printf("%d",MaxSubseqSum(a,N));
return 0;
}
int MaxSubseqSum(int A[] ,int N)
{ int ThisSum ,MaxSum;
int i;
ThisSum = MaxSum = 0;
for(i = 0; i < N; i++)
{ ThisSum += A[i];
if(ThisSum > MaxSum)
MaxSum = ThisSum;
if(ThisSum < 0) ThisSum = 0;
}
return MaxSum;
}
追问
谢谢解答,你的没问题,可以说下我的代码是什么问题吗,谢谢了
追答
你注意对比一下就可以了啊。我的程序是在你的程序的基础上作了修改而已。
最明显的一个问题,你的程序,没有输入数组中的元素,怎么能计算呢?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询