欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    C语言编程学习课件 (23).pdf

    • 资源ID:57972713       资源大小:1.31MB        全文页数:16页
    • 资源格式: PDF        下载积分:8金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要8金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    C语言编程学习课件 (23).pdf

    Programming In CProgramming In C 01 02 03 while statement do-while statement for statement General principle to choose loop statement 04 Contents The while statement Syntax of while statement Execution process while(expression)loop body;“expressionexpression”is a loop conditionis a loop condition,which can be a constant,a variable,or any which can be a constant,a variable,or any type of expression.Usually it is a relational expression or a logical type of expression.Usually it is a relational expression or a logical expression.The loop body consists of one or more statements.expression.The loop body consists of one or more statements.(1 1)Calculate the expression value after while.If the value is Calculate the expression value after while.If the value is true,execute the following step(2).Otherwise,skip it and true,execute the following step(2).Otherwise,skip it and continue to execute the statement after the structure.continue to execute the statement after the structure.(2 2)Execute the loop body statement.Execute the loop body statement.(3 3)Repeat step(1).Repeat step(1).Flow chart Instruction for while statement(1 1)End of the loop is controlled by the expression End of the loop is controlled by the expression following the while.following the while.There must be a statement in the loop There must be a statement in the loop body that changes the value of the loop control variable to body that changes the value of the loop control variable to end the loop.Otherwise,it will lead to an endless loopend the loop.Otherwise,it will lead to an endless loop.(2 2)If there is more than one statements in the loop body,If there is more than one statements in the loop body,it must be enclosed in braces.If there is only one it must be enclosed in braces.If there is only one statement,the braces can be omitted.statement,the braces can be omitted.Instruction Loop body TrueTrue FalseFalse ExpressionExpression while statement programing apply Program to realize the cumulative sum of 1-10.Algorithm analysis:Flow chart:true false i10 sum=sum+i i=i+1 sum=0,i=1 1.Define two integer variables1.Define two integer variables;2.2.Assign corresponding initial values to ssign corresponding initial values to two variablestwo variables(initialize initialize the loop control the loop control variable);variable);3 3、whilewhile statementstatement(set loop conditionset loop condition););4 4、Calculate the sumCalculate the sum(loop body loop body););5 5、Augend changeAugend change(loop control variable loop control variable changechange););6.Output the accumulation sum6.Output the accumulation sum;Code:#includestdio.h void main()Running result:sum=55 int sum,i;sum=0;i=1;while(i=10)sum=sum+i;i+;printf(sum=%dn,sum);while statement programing apply Program to realize the cumulative sum of 1-10.do-while statement do loop body;while(expression);(1 1)Execute the loop body statement.(2 2)Calculate the expression value after while.If the value is true,execute step(1).Otherwise,skip it and continue to execute the statement after the structure.(3 3)Repeat Step(1).Flow chart Loop body expressionexpression false true Syntax of while statement Execution process true false i10 sum=sum+i i=i+1 sum=0,i=1 1.Define two integer variables 1.Define two integer variables 2.2.Assign corresponding initial values to ssign corresponding initial values to two variablestwo variables(initialize initialize the loop control the loop control variable);variable);3.Calculate the sum3.Calculate the sum(loop body);loop body);4.Augend change4.Augend change(loop control variable loop control variable changechange);5.while5.while statementstatement(set loop conditionset loop condition)6.Output the accumulation sum.6.Output the accumulation sum.do-while statement programing apply Program to realize the cumulative sum of 1-10.Algorithm analysis:Flow chart:Code:#includestdio.h void main()Running result:sum=55 int sum,i;sum=0;i=1;do sum=sum+i;i+;while(i=10);printf(sum=%dn,sum);do-while statement programing apply Program to realize the cumulative sum of 1-10.Compare while and do-while statement main()int sum=0,i;scanf(%d,&i);while(i=10)sum=sum+i;i+;printf(sum=%dn,sum);main()int sum=0,i;scanf(%d,&i);do sum=sum+i;i+;while(i=10);printf(sum=%dn,sum);Running result:1 sum=55 Running again:11 sum=0 Running result:1 sum=55 Running again:11 sum=11 for statement(1 1)Execute e1.This part is usually used to calculate the initial Execute e1.This part is usually used to calculate the initial value(execute only once).value(execute only once).(2 2)Execute e2.The condition is evaluated in this part:if the Execute e2.The condition is evaluated in this part:if the value is true,then execute step(3),otherwise skip it and continue value is true,then execute step(3),otherwise skip it and continue to execute the statement following the structure.to execute the statement following the structure.(3 3)Execute the loop body statement.Execute the loop body statement.(4 4)Execute e3 to update the loop control variable.Execute e3 to update the loop control variable.(5 5)Repeat Step(2).Repeat Step(2).for(Initializer expression e1;Conditional expression e2;Incremental expression e3)loop body;Syntax of while statement Execution process Flow chart:1.Define two integer variables1.Define two integer variables;2 2、initialize variableinitialize variable;3 3、for statementfor statement(initial values,initial values,condition and incrementcondition and increment););4.Calculate the sum4.Calculate the sum(loop body);loop body);5.Output the accumulation sum.5.Output the accumulation sum.true false i10 sum=sum+i sum=0,i=1 i=i+1 Instruction for the for statement Program to realize the cumulative sum of 1-10.Algorithm analysis:Code:#includestdio.h void main()Running result:sum=55 int sum=0,i;for(i=1;i=10;i+)sum=sum+i;printf(sum=%dn,sum);Program to realize the cumulative sum of 1-10.Instruction for the for statement Flow chart Instruction for the for statement Instruction true false Condition e2 Loop body Initializer expression e1 Incremental expression e3(1 1)If there is more than one statement in it,loop If there is more than one statement in it,loop body should be enclosed in braces.If there is only body should be enclosed in braces.If there is only one statement in,braces can be omitted.one statement in,braces can be omitted.(2 2)Three expressions in parentheses after the Three expressions in parentheses after the for can be written in other positions according to for can be written in other positions according to their execution order and functions,but no matter their execution order and functions,but no matter how to change,the;in the parentheses cannot be how to change,the;in the parentheses cannot be omitted.omitted.General principle to choose loop statement If the number of repetitions is known and the loop is If the number of repetitions is known and the loop is controlled by counting.controlled by counting.for statement for statement If the number of repetitions is unknown and conditional If the number of repetitions is unknown and conditional control loop is adopted.control loop is adopted.while statementwhile statement If the loop body is to be executed at least once.If the loop body is to be executed at least once.dodo-while statementwhile statement This is just a This is just a generalgeneral principle.principle.Programming In CProgramming In C

    注意事项

    本文(C语言编程学习课件 (23).pdf)为本站会员(刘静)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开