#include <stdlib.h>
/* 1。根据学生信息定义一个结构体类型,再说明一个该结构体类型的数组。*/
struct stu_info{
char stuNo[10]/* No */
char stuName[30]/* Name */
float stuScore[3]/* the three scores */
float aveScore/* average score */
float totalScore/* total score */
}stu[10]
/* 2。用input函数从键盘上输入10个学生的数据。 */
void input()
{ int i = 0
printf("Input the students' infomation(FORMAT LIKE:No Name score1 score2 score3):\n")
while(i <10)
{printf("Input %d:",i + 1)
scanf("%s%s%f%f%f",stu[i].stuNo,stu[i].stuName,&stu[i].stuScore[0],&stu[i].stuScore[1],&stu[i].stuScore[2])
i++
}
}
/* 3。用average函数求出每个学生总成绩、平均成绩和所有学生的总平均成绩。 */
float average()
{ int i = 0
float totalAve_score = 0
while(i <10)
{ stu[i].totalScore = stu[i].stuScore[0]+stu[i].stuScore[1]+stu[i].stuScore[2]
stu[i].aveScore = stu[i].totalScore/3
totalAve_score += stu[i].aveScore
i++}
totalAve_score /= 10
return totalAve_score}
/* 4。用maximum函数找出最高分的学生的数据。 */
int maximun()
{int i = 0, k=0
float tmp=stu[0].totalScore
while(++i <10)
{ if(tmp <stu[i].totalScore)
{tmp = stu[i].totalScore
k = i
}
}
return k
}
/* 5。在主函数中输出每位学生的学号、姓名、三门课成绩、总成绩和平均成绩以及总平均分和最高分学生的数据。*/
int main(int argc, char *argv[])
{ int i = 0, highestNo
float totalAve_score
input() totalAve_score = average()
highestNo = maximun()
printf("NO.\t Name\tScore1\tScore2\tScore3\tTotal\taverage\n")
for(i = 0i <10i++)
printf("%s %s\t %.1f\t%.1f\t%.1f\t%.2f\t%.2f\n",stu[i].stuNo,stu[i].stuName,stu[i].stuScore[0],stu[i].stuScore[1],stu[i].stuScore[2],stu[i].totalScore,stu[i].aveScore)
printf("average = %.2f\n",totalAve_score)
printf("The highest score:%s,score total:%.2f",stu[highestNo].stuName,stu[highestNo].totalScore)
system("PAUSE")
return 0
}