归尘


私信TA

用户名:a2069084072

访问量:818

签 名:

归尘

等  级
排  名 2804
经  验 2071
参赛次数 2
文章发表 8
年  龄 0
在职情况 学生
学  校 中南林业科技大学涉外学院
专  业 计算机科学与技术

  自我简介:

木叶飞舞之处,火亦生生不息!

TA的其他文章

解题思路:

注意事项:结构体中字符串赋值需要用到<string.h>库函数中的strcpy来赋值,主函数中的(struct student s[20];)用来定义结构体中的学生数目的数组,因为不确定输入多少个,所以应该将[ ]中的数字写大点。(20个测试够用)

参考代码:

#include "stdio.h"

#include "string.h"

struct student

{

char xh[20];

char name[20];

int a;

int b;

int c;

};

int main()

{

int x,v,k=0;

scanf("%d",&x);

struct student s[20];//**

char q[20],w[20];int f,g,h;

for (v=0;v<x;v++)

{

scanf("%s %s %d %d %d",q,w,&f,&g,&h);

strcpy(s[k].xh,q);

strcpy(s[k].name,w);

s[k].a=f;

s[k].b=g;

s[k++].c=h;

}

for (int p=0;p<x;p++)

printf("%s,%s,%d,%d,%d\n",s[p].xh,s[p].name,s[p].a,s[p].b,s[p].c);

}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区