- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
loops---while, for while (expression) block; for (statement1; statement2; statement3;) block; while while (expressions) block1; block2; if the value of expression is TRUE,block1 executed and expression revalued,the circle continues till expression become FALSE,then block2 executed. if the value of expression is FALSE,block1 ignored, block2 executed. example: pw.c程序的运行情况。 main() {int num=0; while(num=2) {num++; printf(\n%d,num); } } 将num的初值设为3后的执行情况。 while (循环条件) 循环体语句 main() { } exercise:output 26 lower letters。 ch=’a’。 output ch(a), next character is ch++; output ch(b), next character is ch++; …… …… output ch(z ), next character is ch++;end。 练习4: Input one positive integer,output it in reverse order。Like this:input 123,output 321。 exercises: 1.有如下程序 #include stdio.h main( ) {int n=9; while(n6){n--;printf(%d,n);} } 该程序段的输出结果是( )。 A)987 B)876 C)8765 D)9876 2.有以下程序段 int k=0; while(k==1)k++; while 循环执行的次数是( )。 A)无限次 B)有语法错,不能执行 C)一次也不执行 D)执行一次 3.在while(x)语句中的x与下面条件表达式等价的是( )。 A)x= =0 B)x= =1 C)x!=1 D)x!=0 ? 4.设有以下程序: #include stdio.h main( ) {int n1,n2; scanf(%d,n2); while(n2!=0) {n1=n2%10; n2=n2/10; printf(%d,n1); } } 程序运行后,如果从键盘上输入1298;则输出结果为______。 5.输入right?回车,则下面程序段的执行结果是______。 #include stdio.h main( ) { char c; while ((c=getchar( ))!=‘?’) putchar(c); } ? notes usually there is no semicolon after for and while statements.if any,it means no block. while (i 100) ; i++; for(i = 0; i 100; i++) ; printf(“%d”,i) ; in the for statements,there commonly is a variable to indicate the looping times, don’t change its value in the looping block. 4. Break It is sometimes convenient to be able to exit from a loop other than by testing at the top or bottom. The break statement provides an early exit from for, while, and do, just as from switch. A break causes the innermost enclosing loop or switch to be exited immediately. /* trim: remove trailing blanks, tabs, newlines *
文档评论(0)