第3章节基本结构[正式].pptVIP

  • 3
  • 0
  • 约1.63万字
  • 约 60页
  • 2017-04-01 发布于四川
  • 举报
第3章节基本结构[正式]

输入分隔符的指定 ◆格式串中两个格式符间有分隔符; ◆格式串两个格式符无间隔字符,以空格、TAB或回车键作为分隔 关系运算注意: if ~ else 配对原则:缺省{ }时,else总是和它上面离它最近的未配对的if配对 3.3.5 switch语句(开关分支语句) 一般形式: switch( 表达式) { case E1: 语句组 1; break; case E2: 语句组 2; break; ……. case En: 语句组 n; break; [default: 语句组 ; break;] } 执行过程: switch 表达式 语句组1 语句组2 语句组n 语句组 …... E 1 E 2 En default case Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 说明: E1,E2,…En是常量表达式,且值必须互不相同 语句标号作用,必须用break跳出 case后可包含多个可执行语句,且不必加{ } switch可嵌套 多个case可共用一组执行语句 如: …… case ‘A’: case ‘B’: case ‘C’: printf(“score60\n”); break; …….. Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. /*ch4_5.c*/ #include stdio.h main() { int c; printf(Enter m or n or h or other:); c=getchar(); switch(c) { case m: printf(\nGood morning!\n);break; case n: printf(\nGood night!\n); break; case h: printf(\nHello!\n); break; default : printf(\n????????\n); break; } } 例 根据输入字母输出字符串 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 例 switch(score) { case 5: printf(“Very good!”); case 4: printf(“Good!”); case 3: printf(“Pass!”); case 2: printf(“Fail!”); default : printf(“data error!”); } 运行结果:score为5时,输出: Very good! Good! Pass! Fail! data error! Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 例 void main() { int x=1,y=0,a=

文档评论(0)

1亿VIP精品文档

相关文档