从键盘上任意输入n个整数(n的值由键盘输入,且n<20),输出该n个整数中所有比其平均值大的数。c语言
时间: 2024-02-11 21:10:03 浏览: 62
好的,以下是C语言代码实现:
```c
#include <stdio.h>
int main() {
int n, sum = 0, count = 0;
float avg;
printf("请输入n的值(n<20):");
scanf("%d", &n);
int nums[n];
// 输入n个整数
for (int i = 0; i < n; i++) {
scanf("%d", &nums[i]);
sum += nums[i];
}
// 计算平均值
avg = (float) sum / n;
// 输出比平均值大的数
for (int i = 0; i < n; i++) {
if (nums[i] > avg) {
printf("%d ", nums[i]);
count++;
}
}
// 若没有比平均值大的数,则输出提示信息
if (count == 0) {
printf("没有比平均值大的数!");
}
return 0;
}
```
希望能对你有所帮助!
阅读全文
相关推荐
![c](https://img-home.csdnimg.cn/images/20250102104920.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![ppt](https://img-home.csdnimg.cn/images/20241231044937.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![cpp](https://img-home.csdnimg.cn/images/20250102104920.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![c](https://img-home.csdnimg.cn/images/20250102104920.png)
![cpp](https://img-home.csdnimg.cn/images/20250102104920.png)