- #include<stdio.h>
- //定义一个函数
- float avg(float a[5]){
- float sum=0.02f;
- for(int i=0;i<5;i++) {
- printf("%0.2f\n",a[i]);
- //求和
- sum+= a[i];
- }
- //求平均值
- return sum/5;
- }
- int main(){
- //定义一个数组
- float a1[5]={96.3,63,56.5,45.8,99};
- //调用函数
- float s=avg(a1);
- printf("avg=%.2f\n",s);
- return 0;
- }
复制代码 |
|