欢迎来到天天文库
浏览记录
ID:18161094
大小:436.50 KB
页数:13页
时间:2018-09-14
《c语言程序设计教程第10章new》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
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章章结构体、共用体和枚举类型195chatn
2、ame[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#include3、ing.h>#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);printf("sex(M/F):");sc4、anf("%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",student1.age);printf("score:%f",s5、tudent1.score);}#includestructdate{intmonth;intday;intyear;};structstudent{longnum;charname[10];charsex;structdatebirthday;charaddr[30];};voidmain(){structstudentstud1={990801,"LiMing",'M',{9,12,1981},"HongKong"};第10章章结构体、共用体和枚举类型195printf("num:%ld",stud1.num);printf("n6、ame:%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[3];structstudent{longintnum;charname[10];7、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章章结构体、共用体和枚举类型195inti;for(i=0;i8、f("num:");scanf("%ld",&stu[i].num
3、ing.h>#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);printf("sex(M/F):");sc
4、anf("%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",student1.age);printf("score:%f",s
5、tudent1.score);}#includestructdate{intmonth;intday;intyear;};structstudent{longnum;charname[10];charsex;structdatebirthday;charaddr[30];};voidmain(){structstudentstud1={990801,"LiMing",'M',{9,12,1981},"HongKong"};第10章章结构体、共用体和枚举类型195printf("num:%ld",stud1.num);printf("n
6、ame:%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[3];structstudent{longintnum;charname[10];
7、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章章结构体、共用体和枚举类型195inti;for(i=0;i8、f("num:");scanf("%ld",&stu[i].num
8、f("num:");scanf("%ld",&stu[i].num
此文档下载收益归作者所有