请教一道C语言编程题

从键盘输入N个学生的学号和每人M门课程的成绩,计算每个学生的总分及平均分。输出内容包括每个学生的学号、学分和平均分。... 从键盘输入N个学生的学号和每人M门课程的成绩,计算每个学生的总分及平均分。输出内容包括每个学生的学号、学分和平均分。 展开
 我来答
415355800
推荐于2017-12-16 · TA获得超过106个赞
知道答主
回答量:73
采纳率:0%
帮助的人:76.6万
展开全部
# include "stdio.h"
# include "stdlib.h"

typedef struct Student
{
int Studentid;
int Chinese;
int mathematics;
struct Student * Next;
int Totalscore;
int average;

}* pStudent;

pStudent initialization(void);
void print(pStudent pH);

int len;
int main(void)
{
pStudent pH = initialization();
print(pH);
return 0;
}

pStudent initialization(void)
{

pStudent pH = (pStudent)malloc(sizeof(Student));
if(NULL == pH)
{
printf("动态内存分配失败,程序结束\n");
exit(-1);
}
pStudent pT;
pT = pH;
pT->Next = NULL;
printf("初始化进行中\n");
printf("请问一共有几个学生:\n");
scanf("%d", &len);

for(int x = 0; x < len; x++)
{
pStudent pNew = (pStudent)malloc(sizeof(Student));
printf("\n正在编辑第%d个学生的信息\n", x+1);
printf("\n学生%d的学号为:\n", x+1);
scanf("%d", &pNew->Studentid);
printf("\n学生%d的语文成绩为:", x+1);
scanf("%d", &pNew->Chinese);
printf("\n学生%d的数学成绩为:", x+1);
scanf("%d", &pNew->mathematics);
pNew->Totalscore = pNew->Chinese + pNew->mathematics;
pNew->average = pNew->Totalscore / 2;
pT->Next = pNew;
pNew->Next = NULL;
pT = pNew;
}
return pH;
}

void print(pStudent pH)
{
pStudent pT = pH;
int i = 1;
while(NULL != pT->Next)
{
pT = pT->Next;
printf("\n正在输出第%d个学生的信息", i);
printf("\n学生%d的学号是%d", i, pT->Studentid);
printf("\n学生%d的语文成绩是%d", i,pT->Chinese);
printf("\n学生%d的数学成绩是%d", i,pT->mathematics);
printf("\n学生%d的总分是%d", i, pT->Totalscore);
printf("\n学生%d的平均分是%d", i,pT->average);
i++;
printf("\n");
}
printf("\n所有学生信息输出完毕\n");
return;
}
/*
这里只有两门课程的成绩,语文,数学,其他都OK了
*/
更多追问追答
追问
太恐怖了吧,这个好多啊,有没有简单点的呀。
追答
不会啊,你学过结构体吗,这里使用了结构体和链表,结构体保存这种数据很方便的,看不懂我可以给你加上注释
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式