- 1、本文档共49页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C语言第六章..ppt
Introduction to Computer(C Programming) Software College , Northeastern University 2007,9 6.1 Introduction For example, suppose we want to calculate the sum of squares of all integers between 1 and 10. We can write a program using the if statement. This program does the following things: Initializes the variable n. Computes the square of n and adds it to sum. Tests the value of n to see whether it is equal to 10 or not. If n is less than 10, the control goes back. Loop Control Structures The C language provides for three constructs for performing loop operations. They are: The while statement. The do statement. The for statement. 6.2 The While Statement The basic format of the while statement is: Rewrite the program loop discussed in Section 6.1 as follows: ------------ ------------ sum=0; n=1; /*Initialization*/ while (n=10) /*Testing*/ { sum=sum+n*n; n=n+1; /*Incrementing*/ } printf(“sum=%d\n”,sum); ------------ ------------ Another example of while statement, which uses the keyboard input is shown below: ------------- ------------- character=‘ ’; while (character != ‘Y’) character=getchar(); xxxxxxxx; ------------- ------------- Example 6.1 A program to evaluate the equation y=xn, when n is a non-negative integer 6.3 The Do Statement The form of the do statement is: A simple example of a do...while loop is: -------------------- do { printf(“Input a number\n”); number=getnum(); } while (number0); --------------------- Another example: -------------------- I=1; /*Initializing*/ sum=0; do { sum=sum+I; /*Incrementing*/ I=I+2; } while (sum40||I10); /*Testing*/ printf(“%d %d\n”, I, sum); --------------------- Program 6.2 A program to print the multiplication table from 1×1 to 12×10 as shown below is given: 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20 24 28 32 36 40 5 10 15 20 25 30 35 40 45
您可能关注的文档
- chp人机交互技术..ppt
- CHP冲突论侯均生西方社会学理论课件华中师范大学考研学习必备..ppt
- CHSE理论与方法论..ppt
- ch习题分析..ppt
- ch人力资源战略..ppt
- ch人力资源规划体系的制定..ppt
- ch人力资源规划的实施..ppt
- CH企业内部激励机制x..ppt
- ch企业国际化战略..ppt
- Ch企业财务管理..ppt
- 2025年江西省时事政治考试试卷带解析必背(有一套).docx
- 2025年河南省公务员考试时事政治考试试卷带解析附完整答案【全优】.docx
- 2025年河南省公务员考试时事政治考试试卷带解析及完整答案【各地真题】.docx
- 2025年辽宁省公务员考试时事政治考试试卷带解析附完整答案【夺冠】.docx
- 2025年河南省时事政治考试试卷带解析含答案【预热题】.docx
- 江西昌河航空工业有限公司校园招聘模拟试题附带答案详解及参考答案1套.docx
- 2025年江西省时事政治考试试卷带解析必背(综合题).docx
- 2024年案件风险防控学习心得体会范例(4篇) .pdf
- 2025年江西省时事政治考试试卷带解析(全国通用).docx
- 2024年竣工验收管理制度(三篇) .pdf
文档评论(0)