C语言编程问题,用结构体,谢谢

定义一个结构类型,可以存储一个学生的姓名、数学和计算机两门课的成绩,输入一个学生的姓名和两门课的成绩到结构体变量中,然后计算并输出其平均成绩及姓名。

第1个回答  2020-06-28
#include<stdio.h>

typedef struct student

{

char name[10];

double score[2];

}Stu;

int main(){

Stu stu;

double ave;

printf("请输入学生姓名:\n");

scanf("%s",stu.name);

printf("请输入学生两门课成绩:\n");

for(int i = 0;i<2;i++){

scanf("%lf",&stu.score[i]);

}

ave = (stu.score[0]+ stu.score[1])/2;

printf("姓名:%s\n平均成绩:%.2lf\n",stu.name,ave);

return 0;

}本回答被网友采纳
相似回答