网站大量收购独家精品文档,联系QQ:2885784924

C语言第六章..ppt

  1. 1、本文档共49页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 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

文档评论(0)

文档资料 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档