#include<stdio.h>int f(int array[],int n,int result[2]){int i,sum=0,count=0;for(i=0;i<n;i++)if(array[i]>0){sum+=array[i];count++;}result[0]=sum;result[1]=count;return result[2];}main(){int x[10],y[20],r[2],j;printf("input array x:\n");for(j=0;j<10;j++) scanf("%d",&x[j]);printf("input array y:\n");for(j=0;j<20;j++) scanf("%d",&y[j]);int f(x[10],10,r[2]); /*函數調用*/printf("The sum of x is:%d\nThere are positive number:%d\n",r[0],r[1]);int f(y[20],20,r[2]); /*函數調用*/printf("The sum of y is:%d\nThere are positive number:%d\n",r[0],r[1]);}
2 回答

德瑪西亞99
TA貢獻1770條經驗 獲得超3個贊
f(x,2,r); /*函數調用*/
printf("The sum of x is:%d\nThere are positive number:%d\n",r[0],r[1]);
f(y,3,r); /*函數調用*/
printf("The sum of y is:%d\nThere are positive number:%d\n",r[0],r[1]);
函數調用的部分修改成以上的形式就可以了。
函數調用的時候,不需要加函數的類型,int。這個函數的形參是int[],所以你傳入的參數也應該是指針,int x[10]的x就是指針。
- 2 回答
- 0 關注
- 205 瀏覽
添加回答
舉報
0/150
提交
取消