3 回答

TA贡献1805条经验 获得超9个赞
#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运行结果为
the average of A is 67
the average of B is 50
2哪是形参?哪是实参?
int average(int array[],int n) 函数中的int array[],int n是形参, int pot_1[5]={99,88,77,66,5};
int pot_2[10]={11,22,33,44,55,99,88,77,66,10};
这两个数组是实参;
3;如果你的调用函数在主函数的前面,就不用定义了,要是在主函数后面,就必须在主函数里先声明,才能用;

TA贡献1776条经验 获得超12个赞
1. 写出程序执行的结果。
答:程序的执行结果是:
the average of A is 67
the average of B is 50
2. 哪是形参?哪是实参?
答:int array[]和int n是形参,pot_1, 5, pot_2和10是实参
3. 程序中是否有函数声明语句?若无为什么不需要?
答:程序中没有函数声明语句,因为int average(int array[],int n)
函数的定义在函数调用之前了。如果是函数的定义放在函数的调用之后的话,则需要在main函数中添加函数声明语句了。如下面这样就需要汪加函数声明了:
#include<stdio.h>
main()
{
int average(int array[],int n);
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));
return 0;
}
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);
}

TA贡献1848条经验 获得超2个赞
1. 写出程序执行的结果。
答:结果如下:
the average of A is 67
the average of B is 50
2. 哪是形参?哪是实参?
答:array和n是形参,pot_1, 5, pot_2和10是实参
3. 程序中是否有函数声明语句?若无为什么不需要?
答:程序中没有函数声明语句,因为函数的实现放在了使用它的语句的前面了
- 3 回答
- 0 关注
- 224 浏览
添加回答
举报