C语言程序设计 循环、数组、函数、和结构体程序设计

2024-12-26 07:17:13
推荐回答(1个)
回答1:

#include
#include
#include
#include
typedef struct strStudent{ /*学生信息—结构体*/
char strName[20];
int stuID;
int scoreA;
int scoreB;
int scoreC;
int scoreTot;
float avrScore;
}coStudent;

int maximum (int x,int y);
float average (int nscore1,int nscore2,int nscore3);
void input (coStudent fast);
int main (void)
{
coStudent strstu[10];
int i,p;
i = 0;
while (i < 10)
{
i++; /*循环次数*/
input(strstu[i]);
if (i > 1)
p = maximum(strstu[i].scoreTot,strstu[i - 1].scoreTot);
}
printf(" NO name score1 score2 score3 total average\n");
for (i = 0;i < 10;i++)
printf("%10d %10s %6d %6d %6d %5d %5.2f\n",strstu[i].stuID,strstu[i].strName,strstu[i].scoreA,strstu[i].scoreB,strstu[i].scoreC,strstu[i].scoreTot,strstu[i].avrScore);
printf("Totle score %5d\n",p);
system("pause");
return 0;
}

int maximum (int x,int y) /*最大值*/
{
return x >= y ? x : y;
}
float average (int nscore1,int nscore2,int nscore3) /*平均成绩*/
{
return (nscore1 + nscore2 + nscore3) / 3;
}
void input (coStudent fast)
{
printf("Please input Student ID:");
scanf("%d",&fast.stuID);
printf("Please input Student's Name:");
scanf("%s",&fast.strName);
printf("Please input score of A:");
scanf("%d",&fast.scoreA);
printf("Please input score of B:");
scanf("%d",&fast.scoreB);
printf("Please input score of C:");
scanf("%d",&fast.scoreC);
printf("\n");
fast.scoreTot = fast.scoreA + fast.scoreB + fast.scoreC;
fast.avrScore = average(fast.scoreA,fast.scoreB,fast.scoreC);
}
你自己试着调试一下,我没有环境