用C语言编写程序,要求有50个学生,要求输出成绩在80分以上的学生的学号和成绩
时间: 2024-01-01 09:06:48 浏览: 53
好的,可以使用C语言编写一个简单的程序来实现你的需求。以下是一个示例程序:
```c
#include <stdio.h>
int main() {
int n = 50; // 学生数
int scores[50] = { 85, 90, 70, 75, 82, 88, 92, 60, 78, 83,
79, 91, 68, 72, 86, 89, 93, 77, 80, 84,
76, 81, 87, 95, 73, 66, 71, 69, 74, 67,
94, 99, 96, 98, 97, 63, 65, 62, 61, 64,
59, 58, 57, 56, 55, 54, 53, 52, 51, 50 }; // 学生成绩数组
int i;
for (i = 0; i < n; i++) {
if (scores[i] >= 80) { // 成绩在80分以上的学生
printf("学号:%d,成绩:%d\n", i + 1, scores[i]);
}
}
return 0;
}
```
这个程序定义了一个包含50个学生的学生成绩数组,然后使用循环遍历数组,输出成绩在80分以上的学生的学号和成绩。你可以根据自己的需求修改数组中的学生成绩。
相关问题
C语言编写程序,建立5个学生的结构记录,包括学号、姓名、成绩,输出平均成绩
以下是一个建立5个学生结构记录的C语言程序,包含学号、姓名、成绩,并输出平均成绩:
```c
#include <stdio.h>
struct student {
int id;
char name[20];
float score;
};
int main() {
struct student stu[5];
float sum = 0, avg;
int i;
for (i = 0; i < 5; i++) {
printf("请输入第%d个学生的学号、姓名、成绩:\n", i+1);
scanf("%d %s %f", &stu[i].id, stu[i].name, &stu[i].score);
sum += stu[i].score;
}
avg = sum / 5;
printf("平均成绩为:%.2f\n", avg);
return 0;
}
```
其中,定义了一个名为 `student` 的结构体,包含了学号(`id`)、姓名(`name`)和成绩(`score`)三个成员变量。在 `main` 函数中,定义了一个包含5个 `student` 结构体的数组 `stu`,并使用 `for` 循环依次输入每个学生的信息,同时累加成绩求和。
最后,计算平均成绩并输出。注意,在输出平均成绩时使用了 `%.2f` 的格式化输出,表示输出浮点数时保留两位小数。
c语言编写一个程序输入5个学生的学号姓名三门课程的成绩,输出所有同学成绩和总分最高的学生
好的,以下是一个简单的 C 语言程序,可以实现你的需求:
```c
#include <stdio.h>
#include <string.h>
struct student {
char id[20];
char name[20];
float score1;
float score2;
float score3;
float total_score;
};
int main() {
struct student stu[5];
int i, max_index;
float max_score = 0;
// 输入学生信息
for (i = 0; i < 5; i++) {
printf("请输入第%d个学生的学号:", i+1);
scanf("%s", stu[i].id);
printf("请输入第%d个学生的姓名:", i+1);
scanf("%s", stu[i].name);
printf("请输入第%d个学生的第一门课程成绩:", i+1);
scanf("%f", &stu[i].score1);
printf("请输入第%d个学生的第二门课程成绩:", i+1);
scanf("%f", &stu[i].score2);
printf("请输入第%d个学生的第三门课程成绩:", i+1);
scanf("%f", &stu[i].score3);
stu[i].total_score = stu[i].score1 + stu[i].score2 + stu[i].score3;
}
// 输出所有学生的信息
printf("所有学生的信息如下:\n");
for (i = 0; i < 5; i++) {
printf("学号:%s\n", stu[i].id);
printf("姓名:%s\n", stu[i].name);
printf("第一门课程成绩:%.2f\n", stu[i].score1);
printf("第二门课程成绩:%.2f\n", stu[i].score2);
printf("第三门课程成绩:%.2f\n", stu[i].score3);
printf("总分:%.2f\n", stu[i].total_score);
printf("\n");
}
// 求总分最高的学生
for (i = 0; i < 5; i++) {
if (stu[i].total_score > max_score) {
max_score = stu[i].total_score;
max_index = i;
}
}
// 输出最高分学生的信息
printf("总分最高的学生是:\n");
printf("学号:%s\n", stu[max_index].id);
printf("姓名:%s\n", stu[max_index].name);
printf("第一门课程成绩:%.2f\n", stu[max_index].score1);
printf("第二门课程成绩:%.2f\n", stu[max_index].score2);
printf("第三门课程成绩:%.2f\n", stu[max_index].score3);
printf("总分:%.2f\n", stu[max_index].total_score);
return 0;
}
```
程序中定义了一个结构体 `student`,用来存储每个学生的信息,包括学号、姓名、三门课程的成绩和总分。程序先循环输入五个学生的信息,然后循环输出每个学生的信息,最后循环求出总分最高的学生,输出该学生的信息即可。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)