天津城市建设学院:《C程序设计语言》 Chapter 5 Control Flow

i The C Programming language Chapter 5 Control Flow 累日工作室# ◆非常感谢天肆掠市建学院 周锦姝老师
The C Programming Language Chapter 5 Control Flow #黑日工作室# 非常感谢 天津城市建设学院 周锦姝老师

i The C Programming language Chapter 5 Control Flow Chapter 5 Control Flow a Overview of c statements a Selected Construction if switch 日 Loops goto and if while and do while or 口 break and continue
The C Programming Language Chapter 5 Control Flow Chapter 5 Control Flow ❑ Overview of C Statements ❑ Selected Construction ▪ if ▪ switch ❑ Loops ▪ goto and if ▪ while and do while ▪ for ❑ break and continue

The C Programming language Chapter 5 Control Flow 5.1 Overview of c statements .C statements: using a semicolon as a statement terminator ☆ Kinds of c statements EXI fye归 Cor as total=total+limit a=3 switch Corhpour func(trents for(tb group dec as i h]l()~ int x=l,y=2, Z statdgrewhile( OT zX+y hcEcontinue printf( %od”,z) break goto return
The C Programming Language Chapter 5 Control Flow 5.1 Overview of C Statements ❖ C statements: using a semicolon “ ;” as a statement terminator ; ❖ Kinds of C statements: • Expression statements:an expression flowed by “;” • Control statements (9): if( )~else~ switch for( )~ while( )~ do~while( ) continue break goto return branches loops others As total=total+limit ; a=3 ; func( ) ; printf(“Hello,world!\n”) ; • Compound statements:using braces {…} to group declarations and statements ,so that they are syntactically equivalent to a single statement. oThere is no “;” after the right brace. As { int x=1,y=2,z ; z=x+y ; printf(“%d”,z) ; }

The C Programming language Chapter 5 Control Flow 5.2 Selected Construction(if and switch) if statement: has three syntax O. if (expression)statement expr flowchart 0 tatement as: if(x>y) printf( %od,, x) ◆·if( expression statement 1 !0 expr else as: if(x>y)max-X ht1 statement2 else max-y
The C Programming Language Chapter 5 Control Flow 5.2 Selected Construction (if and switch) ❖ if statement: has three syntax ▪ if (expression) statement ▪ flowchart expr statement !0 =0 as : if (x>y) printf(“%d”,x); expr statement1 statement2 !0 =0 ▪ if (expression) statement1 else statement2 ▪ flowchart as:if (x>y) max=x ; else max=y ;

i The C Programming language Chapter 5 Control Flow if expr1) statement l else if(expr2) statement2 else if(expr3) Statement as: if(salary> 1000) dex=0. 4 else if(salary>800) index=0.3 else if(salary> 600 index=0.2 else if(salary>400 index=0.1 else index=0 非0 statemnt1 statemnt2 statemnt3 statemntn
The C Programming Language Chapter 5 Control Flow ▪ if ( expr1 ) statement1 else if (expr2 ) statement2 else if (expr3 ) statement3 …... [ else statement n ] expr1 statemnt1 非0 =0 expr2 expr3 statemnt2 statemnt3 statemntn 非0 非0 =0 =0 ▪ flowchart: as: if (salary>1000) index=0.4; else if (salary>800) index=0.3; else if (salary>600) index=0.2; else if (salary>400) index=0.1; else index=0;

The C Programming language Chapter 5 Control Flow Notice ◆If( expression the value may be any type statement be compound statement as #include main( a=b, x-Y) i int,y scanf(%od, %od,, &x, &y) if(x>y) cy, y-X Compile error else X++;y++; printf(%d, %dn”2x2y)
The C Programming Language Chapter 5 Control Flow as: if (a==b&&x==y) printf(“a=b,x=y”); if (3) printf(“OK”); if (‘a’) printf(“%d”,’a’); Notice: ◆ If (expression) ◆ if (x) if (x!=0) if(!x) if(x==0) as: #include main() { int x,y; scanf(“%d,%d”,&x,&y); if(x>y) x=y; y=x; else x++; y++; printf(“%d,%d\n”,x,y); } Compile Error! the value may be any type statement may be compound statement

The C Programming language Chapter 5 Control Flow 例求一个数的绝对值 ch5 1.c*/ #include absolute value: %odn"x ,y) Enter an integer:-12 integer: -12--->absolute value: 12
The C Programming Language Chapter 5 Control Flow /*ch5_1.c*/ #include main() { int x,y; printf("Enter an integer:"); scanf("%d",&x); y=x; if(yabsolute value:%d\n",x,y); } 例 求一个数的绝对值 Enter an integer: -12 integer:-12--->absolute value :12

The C Programming language Chapter 5 Control Flow 例输入两个数并判断两数相等否 ch5 2.c*/ #include <stdio h main( Enter integer a: 12 int a b printf("Enter integer a. \ Enter integer b: 12 a==b scan f( 0d",&a) printf( Enter integer b: scanf(%/od", &b) Enter integer a: 12 if(a==b Enter integer b: 9. printf( a==bn") !-=b else printf(al=bn)
The C Programming Language Chapter 5 Control Flow /*ch5_2.c*/ #include main() { int a,b; printf("Enter integer a:"); scanf("%d",&a); printf(“Enter integer b:"); scanf("%d",&b); if (a= =b) printf(“a= =b\n"); else printf(“a!=b\n"); } 例 输入两个数并判断两数相等否 Enter integer a:12 Enter integer b:12 a= =b Enter integer a:12 Enter integer b:9 a!=b

The C Programming language Chapter 5 Control Flow 例判断输入字符种类 /*ch53.c*/ #include maint char c printf("Enter a character c=getchar if(c=o'&&c=A'&&c=a'&&c<=z) printf( "The character is a lower letterin") else printf("The character is other character n") :: Enter a character:& The character is other character
The C Programming Language Chapter 5 Control Flow /*ch5_3.c*/ #include main() { char c; printf("Enter a character:"); c=getchar(); if(c='0'&&c='A'&&c='a'&&c<='z') printf("The character is a lower letter\n"); else printf("The character is other character\n"); } 例 判断输入字符种类 运行:Enter a character: The character is a control character :8 The character is a digit 运行: Enter a character: D The character is a capital letter 运行: Enter a character: h The character is a lower letter Enter a character:& The character is other character

The C Programming language Chapter 5 Control Flow U if statement can be nested if(expr1) if(expr1) if(expr2) if(expr 2) nested if statement 1 nested if statement 1 else statement2 statement2 if(expr1) if (expr1) statement 1 if (expr 2) statement I nested if else else statement2 if(expr 2) statement2 hested if if(expr 3) statement else statement nested if statement
The C Programming Language Chapter 5 Control Flow ❑ if statement can be nested: if (expr1) if (expr2) statement1 else statement2 else if (expr3) statement3 else statement4 nested if nested if if (expr1) if (expr2) statement1 else statement2 nested if if (expr1) if (expr2) statement1 else statement2 nested if if (expr1) statement1 else if(expr2) statement2 else statement3 nested if
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 天津城市建设学院:《C程序设计语言》 Chapter 4 Input and Output.ppt
- 天津城市建设学院:《C程序设计语言》 Chapter 3 Data types, Operators, and Expressions.ppt
- 天津城市建设学院:《C程序设计语言》 第二章 算法 algorithm.ppt
- 天津城市建设学院:《C程序设计语言》 第十二章 文件.ppt
- 天津城市建设学院:《C程序设计语言》 第十一章 结构体与共用体.ppt
- 天津城市建设学院:《C程序设计语言》 Chapter 1 An Overview of c.ppt
- 《计算机导论》课程教学资源(PPT课件)第四章 高级语言软件开发能力培养.ppt
- 《计算机导论》课程教学资源(PPT课件)第三章 计算机操作能力培养.ppt
- 《计算机导论》课程教学资源(PPT课件)第七章 计算机网络能力培养.ppt
- 《计算机导论》课程教学资源(PPT课件)第六章 多媒体应用能力培养.ppt
- 《计算机导论》课程教学资源(PPT课件)第五章 信息系统开发能力培养.ppt
- 《计算机导论》课程教学资源(PPT课件)第二章 计算机硬件能力培养.ppt
- 《计算机导论》课程教学资源(PPT课件)第一章 计算机基础知识.ppt
- 《VisuaI Basic程序设计教程》 编程题答案.doc
- 《VisuaI Basic程序设计教程》 课程介绍.ppt
- 《VisuaI Basic程序设计教程》 教学安排.doc
- 《VisuaI Basic程序设计教程》 教学大纲.doc
- 《VisuaI Basic程序设计教程》 第三章 课堂讨论.ppt
- 《VisuaI Basic程序设计教程》 第三章 赋值与输入输出.ppt
- 《VisuaI Basic程序设计教程》 第二章 课堂讨论.ppt
- 天津城市建设学院:《C程序设计语言》 Chapter 7 Arrays.ppt
- 天津城市建设学院:《C程序设计语言》 Chapter 8 Functions.ppt
- 天津城市建设学院:《C程序设计语言》 第九章 预处理命令.ppt
- 天津城市建设学院:《C程序设计语言》 曲型考题.ppt
- 《C程序设计语言》课程PPT教学课件(讲稿)第一章 An Overview of C(1.2)The feature of C.ppt
- 中国科学技术大学:《计算机安全》课程教学资源(教案讲义)第一章 准备.doc
- 中国科学技术大学:《计算机安全》课程教学资源(教案讲义)第六章 Unix的安全.doc
- 中国科学技术大学:《计算机安全》课程教学资源(教案讲义)第十四章 数据库安全.doc
- 中国科学技术大学:《计算机安全》课程教学资源(教案讲义)第十一章 万维网WwW安全.doc
- 中国科学技术大学:《计算机安全》课程教学资源(教案讲义)第十章 分布式系统安全.doc
- 中国科学技术大学:《计算机安全》课程教学资源(教案讲义)第十二章 密码学介.doc
- 中国科学技术大学:《计算机安全》课程教学资源(教案讲义)第十三章 网络安全.doc
- 《Visual FoxPro程序设计》 第一章 Visual FoxPro基础.ppt
- 《Visual FoxPro程序设计》 第七章 数组.ppt
- 《Visual FoxPro程序设计》 第三章 表单设计与应用.ppt
- 《Visual FoxPro程序设计》 第九章 菜单和自定义工具栏.ppt
- 《Visual FoxPro程序设计》 第二章 Visual Foxpro程序设计基础.ppt
- 《Visual FoxPro程序设计》 第五章 选择结构程序设计.ppt
- 《Visual FoxPro程序设计》 第八章 自定义属性和方法.ppt
- 《Visual FoxPro程序设计》 第六章 循环结构程序设计.ppt