c语言程序设计教程第10章

c语言程序设计教程第10章

ID:17891872

大小:436.50 KB

页数:13页

时间:2018-09-08

c语言程序设计教程第10章_第1页
c语言程序设计教程第10章_第2页
c语言程序设计教程第10章_第3页
c语言程序设计教程第10章_第4页
c语言程序设计教程第10章_第5页
资源描述:

《c语言程序设计教程第10章》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、195结构体、共用体和枚举类型10.1结构体类型与变量的定义10.1.1结构体类型的定义structstudent{longintnum;charname[10];floatscore1,score2,score3;};structstudentstudent1,student2;图10.1structstudent类型量结构图10.2数组作为结构体成员10.1.2结构体类型的嵌套定义structdate{intmonth;intday;intyear;};structstudent{longintnum;第10章章结构体、共用体和枚举类型1

2、95chatname[10];charsex;structdatebirthday;charaddr[30];}student1,student2;图10.3结构体的嵌套结构10.1.3结构体变量的初始化structstudent{longintnum;charname[10];charsex;intage;floatscore;}student1={9908001,"LiMing",'M',19,87.5};图10.4初始化后结构体变量各成员的值图10.5嵌套结构的结构体变量的初始化10.2结构体类型变量的引用#include

3、h>#include#defineSTUstructstudentSTU第10章章结构体、共用体和枚举类型195{longnum;charname[10];charsex;intage;floatscore;};voidmain(){STUstudent1;printf("num:");scanf("%ld",&student1.num);/*输入student1的各成员值*/printf("name:");getchar();/*滤掉输入student1.num后所加的回车符*/gets(student1.name);p

4、rintf("sex(M/F):");scanf("%c",&student1.sex);printf("age:");scanf("%d",&student1.age);printf("score:");scanf("%f",&student1.score);/*输出student1的各成员值*/printf("num:%ld",student1.num);printf("name:%s",student1.name);printf("sex:%c",student1.sex);printf("age:%d",student

5、1.age);printf("score:%f",student1.score);}#includestructdate{intmonth;intday;intyear;};structstudent{longnum;charname[10];charsex;structdatebirthday;charaddr[30];};voidmain(){structstudentstud1={990801,"LiMing",'M',{9,12,1981},"HongKong"};第10章章结构体、共用体和枚举类型195prin

6、tf("num:%ld",stud1.num);printf("name:%s",stud1.name);printf("sex:%c",stud1.sex);printf("birthday:%d/%d/%d",stud1.birthday.month,stud1.birthday.day,stud1.birthday.year);printf("address:%s",stud1.addr);}10.3结构体数组structstudent{longintnum;charname[10];floatscore;}stus

7、[3];structstudent{longintnum;charname[10];floatscore;}stus[3]={{990801,"LiMing",92.5},{990802,"LuYun",89.0},{990803,"YangHong",96.5}};#defineMAX30#includestructstuscore{longintnum;charname[10];intscore[3];inttotal;};voidmain(){structstuscorestu[MAX];第10章章结构体、共用体和枚举

8、类型195inti;for(i=0;i

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。