已阅读5页,还剩18页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Ch5SelectionStatements,ProgrammingConstruct,1)Wedividethebasicprogrammingconstructintothreetypes:SequentialStructure、SelectionStructureandLoopStructure.2)FlowChart(流程图):isagraphicalrepresentationinwhichspecificsymbolsandnecessarylettersareusedtodescribethesteps.3)Theflowchartaboutthethreebasicprogrammingconstructisasfollows:,Sequentialstructure,SelectionStructure,SelectionStructure,1、relationoperatorandrelationexpression,2、logicaloperatorsandlogicalexpression,3、ifstatements,4、switchstatements,5、examples,ChapterOutline,Threeforms:,(1)if(expression)statements(2)if(expression)statements1elsestatements2(3)if(expression1)statements1elseif(expression2)statements2elseif(expression3)statements3elseif(expressionm)statementsmelsestatementsn,ex,ex,ex,BriefSummary,Forme1:if(expression)statements,F(0),T(not0),ex:if(xy)printf(“%d”,x);Firstly,solvetheexpression.Ifthevalueoftheexpressionisnotzero,thenthecorrespondingststementsequenceisexcuted.Ifnoneoftheexpressionisfalse,thenexcutethestatementsafterifderectly.,example,ex:if(xy)printf(“%d”,x);elseprintf(“%d”,y);,Form2:if(expression)statements1elsestatements2,example,ex:if(number500)cost=0.15;elseif(number300)cost=0.10;elseif(number100)cost=0.075;elseif(number50)cost=0.05;elsecost=0;,Form3:nested-ifstatements,example,(1)Theexpressionofthreeformsbehindif-statementsalwaysislogicalorrelationexpression.,DCLofthreeif-statementsforms:,(2)Inform2andforme3,thereisasemicoloninfrontofelse,alsointheendofallstatements.,(3)Behindiforelse,itmayincludeonlyoneoperatestatements,alsoincludemanystatements,butshouldbedrawedtogetherwithbrace.(),Ex:#includemain()intx,y;scanf(“%d,%d”,CompileError!,ex:if(a+ba,Notice:Thebrace(“”)souterfaceneednotsemicolon。Becauseinthebrace()thereisafullcompoundstatement.,originalprogram:main()floata,b,t;scanf(“%f,%f”,ex1:Inputtwerealnumbers,pleaseoutputtherenumbersaccordingtotheorderoflittletobig.,Needthreefloatvariables:a,b,t,ex2:Inputthreerealnumbers,pleaseoutputtherenumbersaccordingtotheorderoflittletobig.,originalprogram:main()floata,b,c,t;scanf(“%f,%f,%f”,Return,#includemain()inta,b;printf(Enterintegera:);scanf(%d,ex3:Iputtwonumbers,decidethemtobeequallyornot.,Result:Enterintegera:12Enterintegerb:12a=b,Result:Enterintegera:12Enterintegerb:9a!=b,Return,Generalform:expression1?expression2:expression3,Conditionoperatorcommandsthreeoperateobjects,itisaoperatoralonelyinClanguage.,ex:max=(ab)?a:b;,Equalto:if(ab)max=a;elsemax=b;,Conditionoperator,DCL:(1)Executionorder:Firstly,solvetheexpression1,,Ifthevalueisture,thensolvetheexpression2,thismomenthereisthevalueofwholeexpressions.,Ifthevalueisfalse,thensolvetheexpression3,thismomenthereisthevalueofwholeexpressions.,ex:max=(ab)?a:b;,Ifa=3,b=4;,max=4;,Ifa=6,b=4;,max=6;,(2)Conditionoperatorovermatchassignedoperator,butunderrelationandarithmeticoperator.,(3)Conditionoperatorscombineddirecionisfromrighttoleft.,ex1:max=(ab)?a:b;,max=ab?a:b;,ex2:max=ab?a:b+1;,max=ab?a:(b+1);,ex3:max=ab?a:cd?c:d;,max=ab?a:(cd?c:d);,Supposea=1,b=2,c=3,d=4,(4)Conditionoperatorcanntreplceordinaryif-statements,onlywhentheembedstatementsinitisassignedstatements(andtwobranchesassigntothesamevariable).,ex:if(ab)printf(“%d”,a);elseprintf(“%d”,b);,printf(“%d”,ab?a:b);,(5)Thetypeofexpression1andexpression2canbesame,alsobedifferent.,ex:intx;x?a:b;,ex:xy?1:1.5;,Ex5:Inputaletter,iudgeitisacapitalletterornot,ifis,thenchangeittolower-caseletter;ifnot,thennothingchanged。Finally,outputthisletter。,main()charch;scanf(“%c“,Return,main()floatx;inty;scanf(“%f”,Return,Algorithm2:inputxifx0y=1outputy,Algorithm3:inputxifx=0)if(x0)y=1;elsey=0;elsey=-1;,p3:modifyto:y=-1;if(x!=0)if(x0)y=1;elsey=0;,p4:modifyto:y=0;if(x=0)if(x0)y=1;elsey=-1;,Return,#includemain()intx,y;print
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 广东省揭阳市揭东区2025-2026学年八年级上学期期末生物学试题(含答案)
- 2027年4月育婴员考试实操技能冲刺卷(完整版)及答案
- 初中数学代数式几何坐标系中三角函数图像平移性质实验研究训练试题及答案
- 初中生物动物骨骼系统结构观察实验设计训练试题及答案
- 2026年高一年级秋学期数学第一周人教A版(2019)必修一周末小测卷及答案
- 2026年江苏省安全员b证考试试题及答案
- 2026年安全生产风险管控考试试题及答案
- 2026年湖北省安全员-B证考试题库及答案
- 2026年龙井市辅警招聘考试真题(附答案)
- 2025年深圳辅警考试试卷真题及答案
- 2026年安全员c3考试题库(含答案)
- 2026秋苏教版六年级数学上册期中考试综合质量检测拔高卷一(含解析)
- 国投集团招录笔试真题2026
- 五年级上册信息技术第三单元第3节《人工智能双刃剑》川教版2024 课件
- 2026国企招聘考试公共基础知识考试题(含答案)
- HSF无有害物质管控培训教材
- 中国MBR膜行业投资潜力分析及发展趋势预测研究报告
- 造物的起源与设计的萌生-原始社会艺术设计课件
- 物流运输调度管理标准工具
- 20xx级学生乐同110kV变电站参观实习概要
- 初一英语完形填空练习题(含答案)(50篇)
评论
0/150
提交评论