《C语言程序设计第五章课件.ppt》由会员分享,可在线阅读,更多相关《C语言程序设计第五章课件.ppt(57页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、2022-8-132/562022-8-133/562022-8-134/562022-8-135/562022-8-136/562022-8-137/562022-8-138/562022-8-139/562022-8-1310/562022-8-1311/562022-8-1312/56Start/EndProcessInput/OutputTestConnectorFlow of activities2022-8-1313/56 2022-8-1314/56ABC2022-8-1315/56 2022-8-1316/562022-8-1317/56Relational Operation
2、DescriptionExamples of ExpressionValueLess than6 91 (true)=Less than or equal to5 Greater than2 60 (false)=Greater than or equal to9 = 51 (true)=Equal to7 = 50 (false)!=Not equal to6 != 51 (true)2022-8-1318/56step aif startstep mstep nend_ifstep b2022-8-1319/56Syntax:复合语句复合语句compound statement被当做一条语
3、句看待被当做一条语句看待2022-8-1320/56Syntax:2022-8-1321/56#include main() int a, b, max; printf(Input a,b:); scanf(%d,%d, &a, &b); if (a b)max = a; if (a = b)max = b; printf(max = %dn, max);Input a,b: _Input a,b: 20 15_Input a,b: 20 15max = 20_2022-8-1322/56Step aif startStep mStep nend_ifelse startStep xStep
4、yend_elseStep z2022-8-1323/56Syntax:or2022-8-1324/562022-8-1325/562022-8-1326/56#include main() int a, b, max; printf(Input a, b:); scanf(%d,%d, &a, &b); if (a b) max = a; else max = b; printf(max = %d, max); if (a b) max = a; if (a = b) max = b;2022-8-1327/56#include main() int a, b, max; printf(In
5、put a, b:); scanf(%d,%d, &a, &b); if (a b) max = a; else max = b; printf(max = %d, max); max = a b ? a : b;2022-8-1328/56Step a (expression1)Step m (expression2) Step n Step z2022-8-1329/56Step a(expression1) Step m (expression2) Step n Step x Step z2022-8-1330/56The structure is similar to multiple
6、 selection (flowchart)2022-8-1331/56Important Rule !2022-8-1332/56Example: switch (month) case 1:printf(Januaryn);break;case 2:printf(Februaryn);break;case 3:printf(Marchn);break;default:printf(Othersn);break; printf(End);January_JanuaryEnd _2022-8-1333/56Example: switch (month) case 1:printf(Januar
7、yn);break;case 2:printf(Februaryn);break;case 3:printf(Marchn);break;default:printf(Othersn);break; printf(End);March_MarchEnd _2022-8-1334/56Example: switch (month) case 1:printf(Januaryn);break;case 2:printf(Februaryn);break;case 3:printf(Marchn);break;default:printf(Othersn);break; printf(End);20
8、22-8-1335/56Example: switch (month) case 1:printf(Januaryn);break;case 2:printf(Februaryn);case 3:printf(Marchn);break;default:printf(Othersn);break; printf(End);2022-8-1336/56Example: switch (month) case 1:printf(Januaryn);break;case 2:printf(Februaryn);case 3:printf(Marchn);break;default:printf(Ot
9、hersn);break; printf(End);February_March _End _2022-8-1337/56Example: switch (month) case 1:printf(Januaryn);break;case 2:printf(Februaryn);case 3:printf(Marchn);break;default:printf(Othersn);break; printf(End);最好不省略最好不省略!2022-8-1338/562022-8-1339/56Why?注释掉会怎样注释掉会怎样? ?2022-8-1340/562022-8-1341/56空格空
10、格2022-8-1342/562022-8-1343/56取绝对值函数取绝对值函数2022-8-1344/56aba & b a | b!a!b0000110101101001011111002022-8-1345/562022-8-1346/56Example: (a = 1) & (b+ = 5) a0b5c15d17尽量使用最少的操作数来确定表达式的值,这就尽量使用最少的操作数来确定表达式的值,这就意味着表达式中的某些操作数可能不会被计算意味着表达式中的某些操作数可能不会被计算2022-8-1347/562022-8-1348/562022-8-1349/56通常结合使用选择有限数量的重要路径进行通常结合使用选择有限数量的重要路径进行白盒测试,对重要的功能需求进行黑盒测试白盒测试,对重要的功能需求进行黑盒测试2022-8-1350/56错在哪里?错在哪里?2022-8-1351/562022-8-1352/562022-8-1353/56错在哪里?错在哪里?2022-8-1354/562022-8-1355/56等腰在先等腰在先等边在后等边在后是否可以是否可以? ?2022-8-1356/56