用数组做函数的参数,计算2个不同长度的数组中所有元素的平均值并打印出来。
已知两数为:
Flaot pot_1 [5]={99,88,77,66,5}
pot_2 [10]={11,22,33,44,55,99,88,77,66,10}
源代码如下
#include<stdio.h>
int average(int array[],int n)
{
int i;
int aver , sum=array[0];
for(i=1;i<n;i++)
sum=sum+array[i];
aver=sum/n;
return(aver);
}
main()
{
int pot_1[5]={99,88,77,66,5};
int pot_2[10]={11,22,33,44,55,99,88,77,66,10};
printf("the average of A is %d\n", average(pot_1,5));
printf("the average of B is %d\n", average(pot_2,10));
while(1);
}
阅读程序回答下列问题:
1. 写出程序执行的结果。
2. 哪是形参?哪是实参?
3. 程序中是否有函数声明语句?若无为什么不需要?
Cats萌萌
叮当猫咪
慕尼黑5688855