用结构体类型编制一程序,实现输入一个学生的数学期中和期末成绩,然后计算并输出平均成绩。
1个回答
展开全部
#include<stdio.h>
struct student{
char name[20];
int midscore;
int finalscore;
float average(){ return (midscore+finalscore)/2;}
};
void main()
{
struct student s1;
printf("输入期中成绩:");
scanf("%d",&s1.midscore);
printf("输入期末成绩:");
scanf("%d",&s1.finalscore);
printf("平均成绩为%4.1f\n",(float)s1.average());
}
struct student{
char name[20];
int midscore;
int finalscore;
float average(){ return (midscore+finalscore)/2;}
};
void main()
{
struct student s1;
printf("输入期中成绩:");
scanf("%d",&s1.midscore);
printf("输入期末成绩:");
scanf("%d",&s1.finalscore);
printf("平均成绩为%4.1f\n",(float)s1.average());
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询