mdzz


私信TA

用户名:mdzz

访问量:18095

签 名:

等  级
排  名 1118
经  验 3035
参赛次数 0
文章发表 29
年  龄 0
在职情况 学生
学  校 pku
专  业

  自我简介:

解题思路:





注意事项:





参考代码:

/*
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可以直接变成结构体数组?
2020-04-05 21:11:25
#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-03-23 21:13:10
受教了,scanf少了&
2020-03-16 22:13:24
为什么成员都是数组呢,不用数组可以吗
2019-11-27 22:50:42
  • «
  • 1
  • »