c作业求源代码 50
2016-04-06
#include "stdio.h"
#include "malloc.h"
typedef struct Student{
char Name[20];
int math;
int Chinese;
int English;
double sum;
double avg;
}Stu;
int main(){
Stu *stu = (Stu *)malloc(sizeof(Stu));
int N;
printf("请输入学生人数:");
scanf("%d", &N);
for (int i = 0; i < N; i++){
printf("请输入你的姓名:");
scanf("%s", &stu[i].Name);
do{
printf("请输入你的数学成绩:");
scanf("%d", &stu[i].math);
} while (stu[i].math>100 || stu[i].math<0);
do{
printf("请输入你的语文成绩:");
scanf("%d", &stu[i].Chinese);
} while (stu[i].Chinese>100 || stu[i].Chinese<0);
do{
printf("请输入你的英语成绩:");
scanf("%d", &stu[i].English);
} while (stu[i].English>100 || stu[i].English<0);
}
for (int i = 0; i < N; i++)
{
stu[i].sum = stu[i].math + stu[i].Chinese + stu[i].English;
stu[i].avg = stu[i].sum / 3;
printf("你的姓名 数学成绩 语文成绩 英语成绩 总分 平均成绩\n");
printf("%s %8d %8d %8d \t %2.lf \t %2.lf\n", stu[i].Name, stu[i].math, stu[i].Chinese, stu[i].English,stu[i].sum,stu[i].avg);
}
getchar();
getchar();
return 0;
}
这是结果: