c语言编程,用结构体记录每位学生的信息,包括姓名数学和计算机成绩,急求,谢谢!

2025-02-23 21:08:55
推荐回答(1个)
回答1:

#include "windows.h"

#include "stdio.h"


#define NAME_LENGTH 32

#define STUDENT_COUNT 3


struct TStudent

{

char szName[NAME_LENGTH];

int nScore1;

int nScore2;

};

void main()

{

printf("输入学生信息:\n");

TStudent arrStudent[STUDENT_COUNT];

for(int i = 0; i < STUDENT_COUNT; i++)

{

scanf("%s %d %d", arrStudent[i].szName, &arrStudent[i].nScore1, &arrStudent[i].nScore2);

}


for(int i = 0; i < STUDENT_COUNT; i++)

{

printf("%s %.1f\n", arrStudent[i].szName, (float)(arrStudent[i].nScore1 + arrStudent[i].nScore2) / 2);

}

system("pause");

return ;

}