表格模板-Chart流程图is 精品.ppt

上传人:lao****ou 文档编号:13468 上传时间:2022-09-21 格式:PPT 页数:23 大小:586KB
下载 相关 举报
表格模板-Chart流程图is 精品.ppt_第1页
第1页 / 共23页
表格模板-Chart流程图is 精品.ppt_第2页
第2页 / 共23页
表格模板-Chart流程图is 精品.ppt_第3页
第3页 / 共23页
表格模板-Chart流程图is 精品.ppt_第4页
第4页 / 共23页
表格模板-Chart流程图is 精品.ppt_第5页
第5页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《表格模板-Chart流程图is 精品.ppt》由会员分享,可在线阅读,更多相关《表格模板-Chart流程图is 精品.ppt(23页珍藏版)》请在第一文库网上搜索。

1、Programming ConstructProgramming Construct1)We divide the basic programming construct into three types:Sequential Structure 、Selection Structure and Loop Structure.2)Flow Chart(流程图):is a graphical representation in which specific symbols and necessary letters are used to describe the steps.3)The flo

2、w chart about the three basic programming construct is as follows:ABconditionABconditionASequential structureSelection StructureSelection Structure1、relation operator and relation expression 2、logical operators and logical expression3、if statements4、 switch statements5、 examplesChapter OutlineThree

3、forms: (1)if(expression)statements (2)if( expression ) statements 1 else statements 2 (3)if( expression 1) statements 1 else if (expression 2) statements 2 else if (expression 3) statements 3 else if(expression m) statements m else statements nexexex第第五五章章选选择择结结构构If语语句句的的形形式式Brief Summary if(express

4、ion)statementsexpressionstatementsF(0)T(not 0)ex: if(xy) printf(“%d”,x); Firstly,solve the expression. If the value of the expression is not zero,then the corresponding ststement sequence is excuted. If none of the expression is false,then excute the statements after if derectly.第第五五章章选选择择结结构构If语语句句

5、的的形形式式exampleexpressionstatements1statements2TFex: if(xy) printf(“%d”,x); else printf(“%d”,y);if(expression)statements1 else statements2第第五五章章选选择择结结构构If语语句句的的形形式式exampleexpression1expression2expression3expression4statements1statements2statements3statements4 statements5FFFFTTTTex: if (number500) cost

6、=0.15; else if (number300) cost=0.10; else if (number100) cost=0.075; else if (number50) cost=0.05; else cost=0;nested- if statements第第五五章章选选择择结结构构If语语句句的的形形式式example (1)The expression of three forms behind if-statements always is logical or relation expression.DCL of three if- statements forms(2)In

7、 form2 and forme3,there is a semicolon in front of else, also in the end of all statements.(3)Behind if or else,it may include only one operate statements,also include many statements ,but should be drawed together with brace.( )第第五五章章选选择择结结构构If语语句句的的形形式式Ex: #include main() int x,y; scanf(“%d,%d”,&x

8、,&y); if(xy) x=y; y=x; else x+; y+; printf(“%d,%dn”,x,y); Compile Error!ex: if(a+ba&c+ab) s=0.5*(a+b+c);area=sqrt(s*(s-a)*(s-b)*(s-c); printf(“area=%6.sf”,area); else printf(“it is not a trilateral”); Notice:The brace( “”)s outer face need not semicolon。Because in the brace() there is a full compoun

9、d statement .第第五五章章选选择择结结构构If语语句句的的形形式式 original program : main() float a,b,t; scanf(“%f,%f”,&a,&b); if(ab) t=a;a=b;b=t; printf(“%5.2f,%5.2f”,a,b); ex1:Input twe real numbers,please output there numbers according to the order of little to big.Need three float variables: a,b,t第第五五章章选选择择结结构构If语语句句举举例例

10、ex2:Input three real numbers,please output there numbers according to the order of little to big.original program : main() float a,b,c,t;scanf(“%f ,%f,%f”,&a,&b,&c);if (ab) t=a;a=b;b=t;if (ac) t=a;a=c;c=t;if (bc) t=b;b=c;c=t;printf(“%5.2f,%5.2f,%5.2f”,a,b,c);第第五五章章选选择择结结构构If语语句句举举例例Return#include ma

11、in() int a,b; printf(Enter integer a:); scanf(%d,&a); printf(Enter integer b:); scanf(%d,&b); if(a=b) printf(a=bn); else printf(a!=bn);ex3 :Iput two numbers ,decide them to be equally or not.Result:Enter integer a:12 Enter integer b:12 a=b Result:Enter integer a:12 Enter integer b:9 a!=b 第第五五章章选选择择结

12、结构构If语语句句嵌嵌套套举举例例ReturnGeneral form:expression1?expression2:expression3 Condition operator commands three operate objects,it is a operator alonely in C language.ex: max=(ab) ? a : b;Equal to : if(ab) max= a; else max=b;第第五五章章选选择择结结构构条条件件运运算算符符Condition operator DCL: (1)Execution order : Firstly,solv

13、e the expression 1, If the value is ture,then solve the expression 2, this moment here is the value of whole expressions.If the value is false, then solve the expression 3, this moment here is the value of whole expressions.ex: max=(ab) ? a : b;If a=3,b=4; max = 4;If a=6,b=4; max = 6;第第五五章章选选择择结结构构条

14、条件件运运算算符符(2) Condition operator overmatch assigned operator,but under relation and arithmetic operator.(3)Condition operators combined direcion is from right to left.ex1:max=(ab) ? a : b;max= ab ? a : b;ex2:max=ab? a : b+1;max= ab ? a : (b+1);ex3:max= ab ? a : c d ? c:d ;max= ab ? a : (c d ? c:d);Su

15、ppose a=1,b=2,c=3,d=4第第五五章章选选择择结结构构条条件件运运算算符符(4) Condition operator cannt replce ordinary if-statements,only when the embed statements in it is assigned statements(and two branches assign to the same variable).ex: if (ab) printf(“%d”,a); else printf(“%d”,b);printf(“%d”,ab?a:b);(5)The type of express

16、ion 1 and expression 2 can be same,also be different.ex: int x; x ? a : b;ex:xy ? 1 :1.5 ;第第五五章章选选择择结结构构条条件件运运算算符符Ex5: Input a letter,iudge it is a capital letter or not ,if is ,then change it to lower-case letter;if not ,then nothing changed。Finally,output this letter。main()char ch;scanf( “ %c “ , &ch);ch = ( ch = A & ch = Z ) ? ( ch + 32 ) : ch ;printf( “ %c “ , ch ) ;第第五五章章选选择择结结构构条条件件运运算算符符Returnex6:Function -1 (x0)y=Write a programme,input the value of x. Then ouput y.main( ) float x ; int

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 技术资料 > 统计图表

copyright@ 2008-2022 001doc.com网站版权所有   

经营许可证编号:宁ICP备2022001085号

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



客服