我收到以下错误:
evenSum.c:9:11: error: subscripted value is neither array nor pointer nor vector
if(array[i] % 2 ==0)
^
evenSum.c:12:15: error: subscripted value is neither array nor pointer nor vector
sum += array[i];
int Even_Sum(int array, int i)
{
for(i = 0; i < 10; ++i)
{
if(array[i] % 2 ==0)
{
int sum=0;
sum += array[i];
return sum;
}
}
}
答案 0 :(得分:1)
要将它用作数组,它应该是:
int Even_Sum(int *array, int i)
或
int Even_Sum(int array[], int i)
无论你在算法的其余部分尝试做什么。
答案 1 :(得分:0)
将Even_Sum
的定义更改为:
int Even_Sum(int *array, int num)
{
int i, sum;
for(i = 0, sum = 0; i < num; ++i)
{
if(array[i] % 2 == 0)
sum += array[i];
}
return sum;
}