




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、C programming language、e.e.buaa、chapter 3:控制流程部件5、chapter 3、page 3-0、控制流程状态规格(semic olon)is a statement terminator分号表示门的结束符号(braces)are used to group declarations and statements together into a compound States=EOF),main() c=min(a,b);Int min(int a,int b)、if(c)!=eof).chapter 3: control flow,c programm
2、ing language,e.e.buaa,3.2 if-else,第3-4页Else statement2、Statement ended with,条件判断,与注释: else最近的if组合,chapter 3: control flow,c programming language,e.e.buaa,3.2 if-else,if(ab)、if (ab)、chapter 3: control flow、c programming language、e.e.buaa、3.2 if-Else(conting Else z=b),if(n0)if(ab)z=a;else z=b;if(n0)if
3、(ab)z=a;else z=b;if-else的范围;chapter 3:control flow,c programming language,e.e. BUAA,3.2 if-I0)printingelse printf(“error-n is a negativen”);note : its a good habit to use braces when there are nested ifs。if(n=0)for(I=0);i0)printf( );else/* wrong */printf( error-n is a negativen );chapter3: controlfl
4、ow,c programming language,e.e.buaa,第3-8页,# includemain () Scanf()或除以400,chapter 3: control flow,version 1st,c programming language,e.e.buaa,page 3-9,# incince scanguageelse if(expression 3)statements 3;Else statementsn、syntax、none of the above、chapter 3: control flow、c programming language、e.e.buaa、
5、3.3 elseC programming language,e.e.buaa,3.3 else-if (continued),第3-12页,int binsearch (int x,)Low=high=n-1;while(lowv mid)low=mid 1;else/* found match */return mid;return 1;/* nomatch */,chapter3: control flow,/*在数组V中搜索数字x的位置*/* V中,元素从小到大*/,c programming language,e.default : statements n;chapter 3: c
6、ontrolflow,c programming language,e.e.buaa,3.3 else-if (continued),page 3 Case b 3360 prrcase c : printf(“6069n”);case d 3360 printf(“60n”);defaut : printf(“errorn”);运行过程:1,如果switch后面的“expression”值等于case后面的“constant expression”值,则牙齿执行case后面的语句(组)。2,如果case后面没有“常量表达式”值,并且与“表达式”值匹配,则牙齿执行default后面的语句(组)
7、。然后执行switch语句中的以下语句:,chapter 3: controlflow,c programming language,e.e.buaa,page 3-15,说明(1)交换机后面的“表达式”(2)否则,会发生徐璐矛盾的现象(即表达式的相同值具有两个或多个执行方案)。(3)case后面的常量表达式仅用作语句标签,不进行条件判断。系统找到入口编号后,将从牙齿编号开始,不再进行标签判断,因此需要添加break语句以结束switch语句。chapter 3: control flow、c programming language、e.e.buaa、page 3-16、switch (gr
8、ade) case a 333 Case b 333case c : printf(“6069n”);case d 3360 printf(“60n”);defaut : printf(“errorn”);输入b。运行结果是什么?7084 6069 60 error,交换机(grade)case a 3360 printf(“85100n”);布列克;case b : printf(“7084n”);布列克;case c : printf(“6069n”);布列克;case d 3360 printf(“60n”);布列克;defaut : printf(“errorn”);break可以停止
9、交换机的进度。chapter 3: control flow、c programming language、e.e.buaa、page 3-17、main NW hite=nother=0;While(c=getchar()!=eof)switch(c)case 03360 case 1: case 2: case : case 4: case 5: case 63360 case 73360 case 73360 case 83360 case 9333330 breakcase : case n : case t :n white;布列克;Default: nother布列克;break
10、statement causes an immediate exit from swicth,back,注意:每个case和default子句的优先级不会影响节目运行结果。共享同一语句(组)的多个case子句。chapter 3: control flow、c programming language、e.e.buaa、3.5 loops-while and for、page 3-18Expr2expr 3)statement;expr1while(expr 2)statement;Expr3,chapter 3: control flow,c programming language,e.e.buaa,3.5 loops-while and for,page 3-19,Expr2expr 3)statement;expr1和expr 3 are assignment or function calls、expr 2 is a relational e
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 健康生活远离疾病课件
- 健康游戏课件幼儿园
- 2025年公用事业行业投资策略分析报告:能源转型开启降本周期
- 营销策划管理岗管理办法
- 蔡甸区矿产开采管理办法
- 蚌埠柴油车管理办法细则
- 西藏新投资项目管理办法
- 衢江区项目报备管理办法
- 西安养老社会化管理办法
- 规范ppp项目管理办法
- 医保drg付费课件培训
- 口腔护士试题及答案
- 彩妆知识培训
- 羊水栓塞护理
- 云南省曲靖市宣威市民中2025届高一化学第二学期期末检测试题含解析
- 2024年宁夏银川金凤区社区专职工作者考试真题
- 2025至2030全球及中国帆船行业产业运行态势及投资规划深度研究报告
- 北京海淀街道社区卫生服务中心招聘笔试真题2024
- 新疆天富能源股份有限公司2024年度商誉减值测试资产评估报告
- 2025年黑龙江龙东地区中考数学试卷真题及答案详解(精校打印)
- 泄密警示教育专题培训
评论
0/150
提交评论