C语言--结构体练习

编程入门 行业动态 更新时间:2024-10-25 00:29:00

C<a href=https://www.elefans.com/category/jswz/34/1770116.html style=语言--结构体练习"/>

C语言--结构体练习

#结构体练习

还有就是要理解:typedef struct和struct的区别(比较混,耐心点QAQ)

这里推荐学习的人去看看(网上有很多)
传送:
作者:bingo~https://www.c…

描述

现有有N个学生的数据记录,每个记录包括学号、姓名、三科成绩。
编写一个函数input,用来输入一个学生的数据记录。
编写一个函数print,打印一个学生的数据记录。
在主函数调用这两个函数,读取N条记录输入,再按要求输出。
N<100。

input

2
a100 zhblue 70 80 90
b200 newsclan 90 85 75

output

100,zhblue,70,80,90
b200,newsclan,90,85,75

#include<stdio.h>
#include<stdlib.h>
struct Student
{char id[20];char name[20];int score1;int score2;int score3;
}stu[100];
void input(int n)
{int i;for(i=0; i<n; i++){scanf("%s %s %d %d %d",&stu[i].id,&stu[i].name,&stu[i].score1,&stu[i].score2,&stu[i].score3);}
}
void output(int n)
{int i;for(i=0; i<n; i++){printf("%s,%s,%d,%d,%d\n",stu[i].id,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3);}
}
int main()
{int n;scanf("%d",&n);struct Student stu[100];input(n);output(n);return 0;
}

更多推荐

C语言--结构体练习

本文发布于:2023-07-28 15:48:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1240095.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语言   结构

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!