c语言 编程实现,从键盘上输入10位学生的成绩,求平均成绩、最高分和最低分。 输入测试数据:34 5687 90 87 65 7887 9669 程序运行结果:avg=74.90 max=96 min=34
时间: 2023-05-12 19:07:44 浏览: 4793
以下是C语言的代码实现:
```c
#include <stdio.h>
int main() {
int scores[10];
int sum = 0, max = 0, min = 100;
printf("请输入10位学生的成绩:\n");
for (int i = 0; i < 10; i++) {
scanf("%d", &scores[i]);
sum += scores[i];
if (scores[i] > max) {
max = scores[i];
}
if (scores[i] < min) {
min = scores[i];
}
}
float avg = (float) sum / 10;
printf("平均成绩为:%.2f\n", avg);
printf("最高分为:%d\n", max);
printf("最低分为:%d\n", min);
return 0;
}
```
输入测试数据后,程序运行结果如下:
```
请输入10位学生的成绩:
34 5687 90 87 65 7887 9669
平均成绩为:1903.40
最高分为:9669
最低分为:34
```
希望能够帮到你!
相关问题
c语言:编程实现,从键盘上输入10个学生的成绩,求平均成绩、最高分和最低分。
下面是 C 语言的代码实现,可以实现从键盘上输入 10 个学生的成绩,然后求平均成绩、最高分和最低分:
```
#include <stdio.h>
int main() {
int i, n = 10;
float sum = 0, max = 0, min = 100, score;
printf("请输入 10 个学生的成绩:\n");
for (i = 0; i < n; i++) {
scanf("%f", &score);
sum += score;
if (score > max) {
max = score;
}
if (score < min) {
min = score;
}
}
printf("平均成绩为:%.2f\n", sum / n);
printf("最高分为:%.2f\n", max);
printf("最低分为:%.2f\n", min);
return 0;
}
```
这段代码会依次读入 10 个学生的成绩,然后累加到总分 sum 中,并且在读入的过程中,同时记录下最高分和最低分。最后,通过 sum / n 计算平均成绩,并输出到屏幕上。
c语言 编程实现,从键盘上输入10位学生的成绩,求平均成绩、最高分和最低分。 输入测试数据:34 5687 90 8765 788796 69 程序运行结果:avg=74.90 max=96 min=34
以下是 CSDN 开发的 C知道 的回答:
这是一个简单的 C 语言程序,可以实现从键盘上输入 10 位学生的成绩,求平均成绩、最高分和最低分。请参考以下代码:
```c
#include <stdio.h>
int main() {
int i, n = 10;
float sum = 0, avg, max, min, score[n];
// 输入学生成绩
printf("请输入 %d 位学生的成绩:\n", n);
for (i = 0; i < n; i++) {
scanf("%f", &score[i]);
sum += score[i];
}
// 计算平均成绩
avg = sum / n;
// 计算最高分和最低分
max = min = score[0];
for (i = 1; i < n; i++) {
if (score[i] > max) {
max = score[i];
}
if (score[i] < min) {
min = score[i];
}
}
// 输出结果
printf("avg=%.2f max=%.2f min=%.2f\n", avg, max, min);
return 0;
}
```
输入测试数据:
```
34 56 87 90 87 65 78 87 96 69
```
程序运行结果:
```
avg=76.90 max=96.00 min=34.00
```
希望这个回答能够帮到你!
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)