结构体 输入5成绩求平均值
程序员文章站
2023-12-26 22:09:03
#include #include void main(){ struct stuscore { char name[20]; float score[5]; float average; }x; int i; float sum; char rep; while ......
#include <stdio.h>
#include <conio.h>
void main()
{
struct stuscore
{
char name[20];
float score[5];
float average;
}x;
int i;
float sum;
char rep;
while(1)
{
printf("\ndo you want to continue?(y/n) ");
rep=getche();
if(rep=='n'||rep=='n'){
printf("\nend");
break;
}
sum=0;
printf("\ninput name(as fan_youyi) and 5 scores(all depart by space);\n");
scanf("%s",x.name);
for(i=0;i<5;i++)
scanf("%f",&x.score[i]);
for(i=0;i<5;i++)
sum+=x.score[i];
x.average=sum/5;
printf("the averrage score of %s is %4.1f\n",x.name,x.average);
}
}