用结构体数组存储3位同学的信息。依次读入3位同学的各项信息,然后计算每位同学的平均分,输出同学的姓名及平均成绩。
例如:
输入:
Meichangsu 81 100
Linshu 90 92
Suzhe 60 70
输出:
Meichangsu 90.5
Linshu 91.0
Suzhe 65.0
#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 ;
}