C程序设计ppt课件

上传人:钟*** 文档编号:5839736 上传时间:2020-02-09 格式:PPT 页数:33 大小:2.74MB
返回 下载 相关 举报
C程序设计ppt课件_第1页
第1页 / 共33页
C程序设计ppt课件_第2页
第2页 / 共33页
C程序设计ppt课件_第3页
第3页 / 共33页
点击查看更多>>
资源描述
第七章预处理命令第九章结构体与共用体 1 7 1 宏调用实现变量a b内容的交换 include defineMYSWAP z x y z x x y y z voidmain floata 5 b 16 c MYSWAP c a b printf f f f n a b c 2 7 2 程序输出结果 36 include definef x x xvoidmain inta 6 b 2 c c f a f b a a b bprintf d n c 3 7 3 程序输出结果 9 840000 include definePR a printf f a defineF y 3 84 y definePRINT a PR a putchar n voidmain intx 2 PRINT F 3 x 4 7 4 swap a b 实现两个参数互换 include defineswap a b a a b b b a a a b 异或 对a和b类型有限制 defineswap a b a a b b a b a a b 求和 对a和b上界有限制voidmain inta b scanf d d 5 7 5 编写宏定义MyLpha c 以判定c是大写字母还是小写字母 当c是小写字母时宏调用取值为1 当c是大写字母时宏调用取值为0 include defineMyLpha c c 97 1 0voidmain charc scanf c 6 9 1a 定义一个图书馆相关信息的结构体类型和结构体变量 其中包括成员书号 书名 作者 出版社和价格 从键盘输入10本图书信息 计算并输出这10本图书的平均价格 include include defineN10typedefstructBookcard charnum 10 charname 30 charauthor 30 charpublisher 60 floatprice Bookcard voidmain Bookcardbook N inti 0 floatmeanprice 0 for i 0 i N i scanf s book i num scanf s book i name scanf s book i author scanf s book i publisher scanf f 7 9 1b include include defineN10typedefstructBookcard charnum 10 charname 30 charauthor 30 charpublisher 60 floatprice Bookcard voidmain 用指针实现赋值Bookcardbook N b floatmeanprice 0 for b book bnum gets b name gets b author gets b publisher scanf f 8 9 2a 在第1题定义的结构体类型中增加一个成员出版日期 该日期是一个嵌套的结构类型变量 其中包括年 月 日 设计一个输入 输出图书馆信息的函数read和print 并编写主函数定义一个10个元素的结构数组 分别调用输入 输出函数输入和输出图书信息 include include defineN10typedefstructDate intyear intmonth intday Date typedefstructBookcard charnum 10 charname 30 charauthor 30 charpublisher 60 floatprice Datedate Bookcard voidread Bookcard p Bookcard b for b p bnum gets b name gets b author gets b publisher scanf f 9 9 2b voidprint Bookcard p Bookcard b for b p bnum puts b name puts b author puts b publisher printf 2f n b price printf d d d n b date year b date month b date day voidmain Bookcardbook N read book print book 10 9 3a 在第2题的基础上 增加一个按书号递增排序的排序函数sort 在主函数中调用排序函数再输出图书信息 voidexchange Bookcard b Bookcard d Bookcardbook1 strcpy book1 num b num strcpy book1 name b name strcpy book1 author b author strcpy book1 publisher b publisher book1 price b price book1 date year b date year book1 date month b date month book1 date day b date day strcpy b num d num strcpy b name d name strcpy b author d author strcpy b publisher d publisher b price d price b date year d date year b date month d date month b date day d date day strcpy d num book1 num strcpy d name book1 name strcpy d author book1 author strcpy d publisher book1 publisher d price book1 price d date year book1 date year d date month book1 date month d date day book1 date day book1 b b d d book1 11 9 3b voidsort Bookcard p Bookcard b d for b p bnum d num 0exchange b d voidmain Bookcardbook N read book sort book print book B0 p b d B1 B2 B3 12 9 4a 建立一个链表 每个节点包括 书号 书名 作者和出版社 并编写按书号查询和删除节点的函数 include include includetypedefstructBookcard charnum 10 charname 30 charauthor 30 charpublisher 60 Bookcard next Bookcard Bookcard create Bookcard head Bookcard p r charnum 10 head NULL gets num while strlen num 0 printf d n strlen num p Bookcard malloc sizeof Bookcard strcpy p num num gets p name gets p author gets p publisher if head NULL head p elser next p r p gets num if r NULL r next NULL printf end n returnhead B0 head r B1 B2 B3 p 13 9 4b voidprint Bookcard p Bookcard b b p while b NULL puts b num puts b name puts b author puts b publisher b b next voidsearch Bookcard p Bookcard b charnum 10 gets num b p while b NULL if strcmp num b num 0 puts b num puts b name puts b author puts b publisher b b next 14 9 4c Bookcard delet Bookcard p Bookcard b pb charnum 10 gets num pb p b p while b NULL if strcmp num b num 0 if b p p b next elsepb next b next returnp pb b b b next voidmain Bookcard head head create print head search head head delet head print head B0 p pb b B1 B2 B3 15 9 5a 根据以下学生情况表 编制一个C语言程序 分别应用选择法和冒泡法对该学生情况表按成绩从低到高进行排序处理并输出 include include defineN5typedefstructStudent charnum 10 charname 10 charsex intage floatgrade Student voidread Student p Student b for b p bnum gets b name scanf c d f 16 9 5b voidprint Student p inti 0 for i 0 inum puts p i name printf c d f n p i sex p i age p i grade 17 9 5c voidsort Student p Student q inti 0 j 0 for i 0 igradegrade q p i p i p j p j q voidmain Studentstu N s N inti for i 0 i N i s i 18 9 6 已知每个学生情况的结点结构类型 1 初始链表为空 2 新结点插入表头 3 输出链表 4 删除结点并输出 include include includetypedefstructStudent charnum 10 charname 10 charsex intage floatgrade Student next Student Student create Student head Student p charnum 10 head NULL gets num while strlen num 0 p Student malloc sizeof Student strcpy p num num gets p name scanf c d f S1 head S0 S2 p 19 9 6b voidprint Student p Student b b p while b NULL puts b num puts b name printf c d 2f n b sex b age b grade b b next B0 p pb b B1 B2 B3 Student delet Student p Student b pb intage scanf d 20 9 6c voidmain Student head head create head delet head print head 21 9 7 13个人围成一圈 从第1个人开始顺序报号1 2 3 凡报到 3 者退出圈子 编程找到最后留在圈子的人原来的序号 include defineN13structperson intnumber intnextp link N 1 voidmain inti count h for i 1 i N i if i N link i nextp 1 elselink i nextp i 1 link i number i count 0 h N while count N 1 i 0 while i 3 h link h nextp if link h number i link h number 0 count for i 1 i N i if link i number printf 3d link i number printf n 22 9 8a 两个链表La和Lb合并成一个递增有序的单链表Lc include include includetypedefstructBookcard charnum 10 charpublisher 60 Bookcard next Bookcard Bookcard create Bookcard head Bookcard p r charnum 10 head NULL gets num while strlen num 0 p Bookcard malloc sizeof Bookcard strcpy p num num gets p publisher if head NULL head p elser next p r p gets num if r NULL r next NULL printf end n returnhead 23 9 8b Bookcard combin Bookcard La Bookcard Lb 把Lb的结点都插入到La中Bookcard pa1 pa2 pb1 pb2 pa1 pa2 La pb1 pb2 Lb do while strcmp pb1 num pa1 num 0 24 A0 La A1 A2 A3 Lb B2 pa2 pa1 pb1 B1 B0 pb2 A0 La A1 A2 A3 B0 Lb B1 B2 pa2 pa1 pb1 pb2 25 9 8c voidmain Bookcard La Lb Lc La create Lb create Lc combin La Lb print Lc 26 9 9a 单链表结构实现直接选择排序 voidprint Bookcard p Bookcard b b p while b NULL puts b num puts b publisher b b next Student create Student head p charnum 10 head NULL gets num while strlen num 0 p Student malloc sizeof Student strcpy p num num gets p name scanf c d f 27 9 9b 单链表结构实现直接选择排序 Student sort Student p Student head Student pnow pnow2 pmin p1 p2 head p pnow head 当前结点pnow2 head pnow先继while pnow next NULL pmin pnow p2 pmin p1 pmin next while p1 NULL if pmin grade p1 grade pmin p1 最小结点p1 p1 next if pmin pnow pnow2 pnow pnow pnow next else while p2 next pmin p2 p2 next pmin先继p2 next pmin next if pnow head head pmin pnow2 head elsepnow2 next pmin pmin next pnow pnow2 pmin returnhead 28 S0 head S1 S3 S4 pnow2 pnow S2 pmin p2 S5 S0 head S1 S2 S3 S4 S5 pnow2 pnow S0 head S1 S3 S4 pnow2 pnow S2 pmin p2 S5 S0 head S1 S2 S3 S4 S5 pnow2 pnow pmin p2 29 9 9c 单链表结构实现直接选择排序 voidprint Student p Student b b p while b NULL puts b num puts b name printf c d 2f n b sex b age b grade b b next voidmain Student head head create head sort head print head 30 谢谢 31 1 intx 2 y z x y z 5 x z 3 x y z x x y z x x y x 10 10 1 3 1 32 2 inta x for a 0 x 0 a 1 a x 2 11 2 33
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 大学资料


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!