你好我目前在运行这个程序时遇到问题。它会不断弹出错误消息,并省略参数名称。有什么建议?
int addarray (int *,int);
int main(void){
int array1 [10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
array2 [4] = {0, 0, 0, 0};
int i;
int total = 0;
int total2 = 0;
for(i=0;i<10;i++){
total += array1[i];
}
for(i=0;i<4;i++){
total2 += array2[i];
}
printf("The sum of the elements in array1 is %d. \n", addarray(array1, 10));
printf("The sum of the elements in array2 is %d. \n", addarray(array2, 4));
return 0;
}
int addarray (int *,int){
int array1 [10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
array2 [4] = {0, 0, 0, 0};
int i;
int total = 0;
int total2 = 0;
for(i=0;i<10;i++){
total += array1[i];
}
for(i=0;i<4;i++){
total2 += array2[i];
}
}
答案 0 :(得分:2)
你必须在addarray函数中为参数命名,例如:
int addarray (int *a, int b) {