#include <stdio.h>
#define N 2
typedef struct { float cp; float en; float math; float db; float phy; } GRADE;
typedef struct { int num; char name[21]; char sex; int age; GRADE grades; float ave; } STUDENT;
void main() { STUDENT stu[N]; STUDENT *p; int i; p = stu; for (i = 0; i < N; i++) { printf("请输入学号: "); scanf("%d", &p->num); printf("请输入姓名: "); fflush(stdin); gets(p->name); printf("请输入性别: "); fflush(stdin); p->sex = getchar(); printf("请输入年龄: "); scanf("%d", &p->age); printf("请输入C语言成绩: "); scanf("%f", &p->grades.cp); printf("请输入英语成绩: "); scanf("%f", &p->grades.en); printf("请输入数学成绩: "); scanf("%f", &p->grades.math); printf("请输入数据库成绩: "); scanf("%f", &p->grades.db); printf("请输入物理成绩: "); scanf("%f", &p->grades.phy); p->ave = (p->grades.cp + p->grades.db + p->grades.en + p->grades.math + p->grades.phy) / 5; p++; }
printf("学号\t姓名\t性别\t年龄\tC语言\t英语\t数学\t数据库\t物理\t平均\n"); p = stu; for (i = 0; i < N; i++) { printf("%d\t%s\t%c\t%d\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n", p->num, p->name, p->sex, p->age, p->grades.cp, p->grades.en, p->grades.math, p->grades.db, p->grades.phy, p->ave); p++; } }
|