C语言程序设计第四版(何钦铭、颜晖)第九章结构之输出平均分
【练习9-3】例9-1中,如果要计算的是三门课程的课程平均分,应该如何改写程序?
#include<stdio.h> struct Student{ int num; char name[10]; int computer,english,math; double average; }; int main(){ struct Student stu; int n,i; scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d%s%d%d%d",&stu.num,stu.name,&stu.computer,&stu.english,&stu.math); stu.average=(stu.computer+stu.english+stu.math)/3.0; printf("The average of %s is %.2f\n",stu.name,stu.average); } return 0; }输入样例:3
111 amy 100 90 98
222 saroy 93 87 100
333 john 98 83 97
输出结果:The average of amy is 96.00
The average of saroy is 93.33
The average of john is 92.67
