输入n(scanf)个学生,分别输入每个学生的学号 姓名 语文成绩 数学成绩 英语成绩, 将成绩表输出,成绩表包括每个学生的 学号 姓名 语文成绩 数学成绩 英语成绩 总分。
时间: 2023-09-06 22:14:13 浏览: 56
这个问题属于编程问题,我可以回答。以下是一个可能的 C 代码实现:
```c
#include <stdio.h>
struct student {
char id[10];
char name[20];
int chinese;
int math;
int english;
int total;
};
int main() {
int n;
scanf("%d", &n);
struct student stu[n];
for (int i = 0; i < n; i++) {
scanf("%s %s %d %d %d", stu[i].id, stu[i].name, &stu[i].chinese, &stu[i].math, &stu[i].english);
stu[i].total = stu[i].chinese + stu[i].math + stu[i].english;
}
printf("学号\t姓名\t语文\t数学\t英语\t总分\n");
for (int i = 0; i < n; i++) {
printf("%s\t%s\t%d\t%d\t%d\t%d\n", stu[i].id, stu[i].name, stu[i].chinese, stu[i].math, stu[i].english, stu[i].total);
}
return 0;
}
```
相关问题
用c语言代码写出:输入n(scanf)个学生,分别输入每个学生的学号 姓名 语文成绩 数学成绩 英语成绩, 将成绩表输出,成绩表包括每个学生的 学号 姓名 语文成绩 数学成绩 英语成绩 总分
好的,这是一个很基础的C语言编程问题,下面是相应的代码:
```c
#include <stdio.h>
struct Student {
int id;
char name[20];
int chinese;
int math;
int english;
int total;
};
int main() {
int n;
printf("请输入学生人数:\n");
scanf("%d", &n);
struct Student students[n];
printf("请依次输入每个学生的学号、姓名、语文成绩、数学成绩和英语成绩:\n");
for (int i = 0; i < n; i++) {
scanf("%d %s %d %d %d", &students[i].id, students[i].name, &students[i].chinese, &students[i].math, &students[i].english);
students[i].total = students[i].chinese + students[i].math + students[i].english;
}
printf("学号\t姓名\t语文成绩\t数学成绩\t英语成绩\t总分\n");
for (int i = 0; i < n; i++) {
printf("%d\t%s\t%d\t%d\t%d\t%d\n", students[i].id, students[i].name, students[i].chinese, students[i].math, students[i].english, students[i].total);
}
return 0;
}
```
当您输入学生数量n和每个学生的详细信息后,程序将按照您的输入打印出成绩表,其中包括每个学生的学号、姓名、语文成绩、数学成绩、英语成绩和总分。如果您还有其他问题,请继续提出。
创建一个动态链表输出三个学生的学号和成绩,以及平均成绩
好的,以下是一个使用动态链表实现的C语言程序,可以输入三个学生的学号和成绩,计算出平均成绩并输出:
```c
#include <stdio.h>
#include <stdlib.h>
// 定义学生结构体
struct student
{
int num;
int score;
struct student* next;
};
int main()
{
int count = 0, sum = 0;
float avg;
struct student *head, *p, *q;
// 初始化链表头节点
head = (struct student*)malloc(sizeof(struct student));
head->next = NULL;
q = head;
// 输入三个学生的学号和成绩
for (int i = 0; i < 3; i++)
{
p = (struct student*)malloc(sizeof(struct student));
printf("请输入第%d个学生的学号和成绩:", i+1);
scanf("%d %d", &p->num, &p->score);
q->next = p;
q = p;
count++;
sum += p->score;
}
q->next = NULL;
// 计算平均成绩
if (count != 0)
{
avg = (float)sum / count;
printf("平均成绩为:%.2f\n", avg);
}
else
{
printf("没有输入成绩!\n");
}
// 输出链表中的学号和成绩
printf("学号\t成绩\n");
p = head->next;
while (p != NULL)
{
printf("%d\t%d\n", p->num, p->score);
p = p->next;
}
// 释放链表内存
p = head;
while (p != NULL)
{
q = p->next;
free(p);
p = q;
}
return 0;
}
```
这个程序使用了动态链表来存储输入的学生信息,每输入一个学生的学号和成绩,程序就会创建一个新的节点,并将其插入到链表的尾部。
在链表建立完成后,程序使用循环遍历链表,计算总成绩和学生数量,然后计算出平均成绩并输出。
最后,程序再次遍历链表,输出每个学生的学号和成绩,并释放链表的内存。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)