用c语言 写求一组数的平均值及高于平均值的个数
时间: 2024-05-19 14:11:17 浏览: 73
C语言程序设计-求一组数中大于平均值的数的个数;例如:给定的一组数为1,3,6,9,4,23,35,67,12,88时,函数值3
5星 · 资源好评率100%
#include <stdio.h>
int main() {
int n, sum = 0, count = 0;
float avg;
printf("请输入数的个数:");
scanf("%d", &n);
int nums[n];
printf("请输入%d个数:\n", n);
for (int i = 0; i < n; i++) {
scanf("%d", &nums[i]);
sum += nums[i];
}
avg = (float)sum / n;
printf("平均值为:%.2f\n", avg);
for (int i = 0; i < n; i++) {
if (nums[i] > avg) {
count++;
}
}
printf("高于平均值的个数为:%d\n", count);
return 0;
}
阅读全文