C语言如何用数组求总人数,最高分,最低分,平均分(某班数学考试成绩:90,78,98,67,53,97,78,100,76,88)
时间: 2024-06-13 17:00:30 浏览: 307
以下是C语言使用数组求总人数、最高分、最低分和平均分的示例代码:
```c
#include <stdio.h>
int main() {
float scores[10] = {90, 78, 98, 67, 53, 97, 78, 100, 76, 88};
int n = 10;
float sum = 0, average, max = scores[0], min = scores[0];
for (int i = 0; i < n; i++) {
sum += scores[i];
if (scores[i] > max) {
max = scores[i];
}
if (scores[i] < min) {
min = scores[i];
}
}
average = sum / n;
printf("总人数:%d\n", n);
printf("最高分:%.1f\n", max);
printf("最低分:%.1f\n", min);
printf("平均分:%.1f\n", average);
return 0;
}
```
输出结果为:
```
总人数:10
最高分:100.0
最低分:53.0
平均分:82.5
```
阅读全文