解题思路:
注意事项:
参考代码:
/* t */ #include<stdio.h> #define N 100 struct student { char num[10]; char name[10]; int score[3]; }; void input(struct student *stu,int n)//把结构体变量正常对待即可 { int i; for(i = 0; i < n; i++) scanf("%s%s%d%d%d",stu[i].num,stu[i].name,stu[i].score,stu[i].score+1,stu[i].score+2); //stu[i].score是score数组的首地址 } void print(struct student *stu,int n) { int i; for(i = 0; i < n; i++) printf("%s,%s,%d,%d,%d\n",stu[i].num,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2]); } int main() { struct student stu[N]; int n; scanf("%d",&n); input(stu,n); print(stu,n); return 0; }
0.0分
15 人评分
void input(struct Stu *stu,int n){ for(int i=0;i<n;i++){ scanf("%s%s%d%d%d",stu[i].id,stu[i].name,stu[i].s1,stu[i].s2,stu[i].s3); } } 这里不是定义了一个结构体指针吗? 为什么下面的scanf可以直接变成结构体数组?
#include<stdio.h> struct Stu { char id[10]; char name[10]; int s1; int s2; int s3; }; void input(struct Stu *stu,int n){ for(int i=0;i<n;i++){ scanf("%s%s%d%d%d",stu[i].id,stu[i].name,stu[i].s1,stu[i].s2,stu[i].s3); } } void output(struct Stu *stu,int n){ for(int i=0;i<n;i++){ printf("%s %s %d %d %d\n",stu[i].id,stu[i].name,stu[i].s1,stu[i].s2,stu[i].s3); } } int main(){ int n; scanf("%d",&n); struct Stu stu[100]; input(stu,n); output(stu,n); return 0; } 为什么不对啊
福卡 2020-05-30 21:43:42 |
可能你输出函数名字写错了吧
C语言训练-排序问题<2> (C++代码)浏览:877 |
wu-淘淘的名单 (C++代码)浏览:1325 |
三角形 (C++代码)递归(存在大量重复计算,容易出现时间超限)浏览:771 |
a+b浏览:432 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:773 |
演讲大赛评分 (C语言代码)浏览:1624 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:562 |
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:565 |
用筛法求之N内的素数。 (C语言代码)浏览:527 |
前10名 (C语言代码)浏览:724 |