|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
是一道补充程序的题目,所以代码并不完整,带*的地方就是需要补充的地方
请问第一行 这里可以直接这样写嘛,不需要 #inlude<stdio.h> 嘛?
然后第12行的 pst->average 是什么意思鸭……
- #include struct STUDENT
- {
- char name[16];
- int math;
- int english;
- int computer;
- int average;
- };
- void GetAverage(struct STUDENT *pst)
- {
- int sum=0;
- sum=/****1****/;
- pst->average=sum/3;
- }
- int main()
- {
- int i;
- struct STUDENT st[4]={{"Jessica",98,95,90},{"Mike",80,80,90}, {"Linda",87,76,70},{"Peter",90,100,99} }; for(i=0;i<4;i++) { GetAverage( /****2****/ ); }
- for(i=0;i<4;i++)
- printf("%s,%d,%d,%d,%d\n",st[i].name,st[i].math,st[i].english,st[i].computer,st[i].average);
- return 0;
- }
复制代码
那两处帮你写好了,你有疑问的地方也帮你写了注释。
- #include <stdio.h>//这里肯定是错的。当然需要加载<stdio.h>文件啦!
- struct STUDENT
- {
- char name[16];
- int math;
- int english;
- int computer;
- int average;
- };
- void GetAverage(struct STUDENT *pst)
- {
- int sum=0;
- sum=pst->math+pst->english+pst->computer;
- pst->average=sum/3; //pst是一个指针,用指针调用成员就是用箭头啊
- }
- int main()
- {
- int i;
- struct STUDENT st[4]={{"Jessica",98,95,90},{"Mike",80,80,90}, {"Linda",87,76,70},{"Peter",90,100,99} };
- for(i=0;i<4;i++){
- GetAverage( &st[i] );
- }
- for(i=0;i<4;i++)
- printf("%s,%d,%d,%d,%d\n",st[i].name,st[i].math,st[i].english,st[i].computer,st[i].average);
- return 0;
- }
复制代码
|
|