《C语言课程设计案例精编》课件 3_第1页
《C语言课程设计案例精编》课件 3_第2页
《C语言课程设计案例精编》课件 3_第3页
《C语言课程设计案例精编》课件 3_第4页
《C语言课程设计案例精编》课件 3_第5页
已阅读5页,还剩73页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Source file_1Source file_iSource file_n.Function_1Function_nFunction_1.C program.exeCompileStatementsDeclaration StatementsExecutive StatementsControl-flow StatementsExpression StatementsNull StatementsCompound StatementsSelection StatementsIteration StatementsJump StatementsComment StatementsLabele

2、d StatementsComment statementDeclaration statementCompound statementSelection statementExpression statementNull statementIdentifier: switchSelection StatementsIf statementIf-else statementswitch statementconditionstatementTrueFalseconditionStatement_1TrueFalseStatement_2#include main( ) int a, b, ma

3、x; printf (Input a and b=); scanf (%d %d, &a, &b); max=a; /* assume a is bigger one */ if ( max b ) max=b; /* b is bigger*/ printf(The max of a and b : %dn, max);max bmax= bTrueFalse#include main( ) int a, b, max; printf (Input a and b=); scanf (%d %d, &a, &b); if ( ab ) max=a; /* ab

4、, a-max */ else max=b; /* amax */ printf (The max of a and b : %dn, max);ab?max=aTruemax=bFalseNotice:Sometimes, If-else statement and condition expression could convert each other! max=(ab) ? a : b ; Condition expressionassignment statementIf-else statementb?a/bTruecannotFalseif (b) printf (“%dn”,

5、a/b);else printf (“error.n”);EquivalentHow to match multiple if and else? A else match with the previous, closest, and no-matching if. if ( x != y ) if ( x y ) printf (XYn); else printf (X=abWhen a=90) printf(An);else if (a=80) printf(Bn);else if (a=70) printf(Cn);else if (a=60) printf(Dn);else prin

6、tf(En);if (a=90) printf(An);if (a=80) printf(Bn);if (a=70) printf(Cn);if (a=60) printf(Dn);if (a=90) printf(An);else if (a=80) printf(Bn); else if (a=70) printf(Cn); else if (a=60) printf(Dn); else printf(En); Stat 1Nexpr 1Yexpr 2expr mYYStat 2Stat mStat nNNelse ifScoresDivide scores into five level

7、s:90,80-89, 70-79, 60-69, =0 & =100) switch (int)(fs/10) case 10: case 9: printf(“An”); break; case 8: printf(“Bn”); break; case 7: printf(“Cn”); break; case 6: printf(“Dn”); break; default: printf(“En”); 将将分分数数分分为为五五个个分分数数段段conditionstatementTrueFalseconditionStatement_1TrueFalseStatement_2Expr

8、ession_1Statement_1Expression_2Statement_2.Expression_nStatement_n Stat 1Nexpr 1Yexpr 2expr mYYStat 2Stat mStat nNNelse if* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *PAAYYNNwhileuntilPwhiledo-whileforIteration StatementswhileuntilexprStatementYNLoop b

9、odyindex =1;While ( - index5) printf (“ Good morning!n”);Dead loop(cannot stop)Dead loop(cannot stop)Conclusion The loop condition should make loop stop normally!Null statementint i=1; while (i = 100) sum += i+;int i=0;while (+i = 100) sum += i;int i=0;while (i + 100) sum += i;int i=0;while (i 100)

10、sum += +i;Iteration Algorithm=100; sum+=; i+i; =100; sum+=;100; i+; sum+=; 100; +i; sum+=;When i=6, j=5Value=301= i = 91= j = istatementExpr?Statement after do-whileNYloop conditionLoop bodyQuestion: how to convert this program by using while structure? What are their differences?Usual form:for (ini

11、tialization; condition; + + or - -)Expr1;Expr2?Expr3;statementNYStatement after forinitializationloop conditionLoop bodyOutput: 1!= 1 2!= 2 3!= 6 4!= 24 5!= 120 6!= 720 7!= 5040 8!= 40320 9!= 362880 10!= 3628800Nested loop structure!嵌套循环结构#include main() int i=1, j; while ( i = 9 ) printf(%4d, i+ );

12、 printf (n-n); i=1; while ( i= 9 ) j = 1; while ( j = i ) printf (%4d, i*j ); j+; printf (n); i+; printf( (j=i)? “%4dn” : “%4d”, i*j);if ( j=i ) printf(“%4dn”, i*j);else printf(“%4d”, i*j);Recurrent Algorithm (递推算法递推算法)In for statement, comma, works as operator, not separator! Parallel-loop structur

13、e! 并列循环结构并列循环结构Jump StatementsbreakcontinuereturngotoLabeled StatementsidentifiercasedefaultExpr?break;Expr?break;expr2?break;expr3;expr1;Statementafter loopStatementafter loopStatementafter loopNYNYNYwhile-structurefor-structuredo-while-structureOutput:N: 555555Divisor: 777 Output:N: 56789Divisor: 521 Expr?continue;Expr?expr2?expr3;expr1;Statementafter loopStatementafter loopStatementafter loo

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论