c语言里面自带的求平均数的函数
时间: 2024-02-06 21:11:24 浏览: 95
C语言中没有自带的求平均数的函数。你需要自己编写代码来计算平均数。以下是一个求平均数的示例代码:
```c
#include <stdio.h>
int main() {
int n;
float sum = 0, avg, num;
printf("请输入数字的个数:");
scanf("%d", &n);
for (int i = 0; i < n; i++) {
printf("请输入数字%d:", i + 1);
scanf("%f", &num);
sum += num;
}
avg = sum / n;
printf("这%d个数字的平均数是:%.2f", n, avg);
return 0;
}
```
该程序通过循环读取用户输入的数字,并累加求和,最后计算平均值并输出。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)