国外C语言程序设计英文课件-lecture3.ppt

国外C语言程序设计英文课件-lecture3.ppt

ID:48029150

大小:169.50 KB

页数:34页

时间:2020-01-11

国外C语言程序设计英文课件-lecture3.ppt_第1页
国外C语言程序设计英文课件-lecture3.ppt_第2页
国外C语言程序设计英文课件-lecture3.ppt_第3页
国外C语言程序设计英文课件-lecture3.ppt_第4页
国外C语言程序设计英文课件-lecture3.ppt_第5页
资源描述:

《国外C语言程序设计英文课件-lecture3.ppt》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、ComputerprogrammingLecture3Lecture3:OutlineProgramLooping[Kochan–chap.5]TheforStatementRelationalOperatorsNestedforLoopsIncrementOperatorProgramInputforLoopVariantsThewhileStatementThedoStatementThebreakStatementThecontinueStatementExecutingaprogramProgram=listofstatementsEntrypoint:thepoin

2、twheretheexecutionstartsControlflow:theorderinwhichtheindividualstatementsareexecutedStatement1Statement2Statement3Statement4Statement5Statement6Statement7Statement8StructureofaCprogram#includeintmain(void){intvalue1,value2,sum;value1=50;value2=25;sum=value1+value2;printf("Thesumof

3、%iand%iis%i",value1,value2,sum);return0;}EntrypointofaCprogramSequentialflowofcontrolControllingtheprogramflowFormsofcontrollingtheprogramflow:ExecutingasequenceofstatementsRepeatingasequenceofstatements(untilsomeconditionismet)(looping)Usingatesttodecidebetweenalternativesequences(branch

4、ing)Statement1Statement2Statement3Statement4Statement5Statement6Statement7Statement8ProgramLoopingLooping:doingonethingoverandoverProgramloop:asetofstatementsthatisexecutedrepetitivelyforanumberoftimesSimpleexample:displayingamessage100times:printf(“hello!”);printf(“hello!”);printf(“hel

5、lo!”);…printf(“hello!”);printf(“hello!”);Repeat100timesprintf(“hello!”);Programlooping:enablesyoutodevelopconciseprogramscontainingrepetitiveprocessesthatcouldotherwiserequiremanylinesofcode!Theneedforprogramlooping#includeintmain(void){inttriangularNumber;triangularNumber=

6、1+2+3+4+5+6+7+8;printf("Theeighthtriangularnumberis%i",triangularNumber);return0;}Whatifwehavetocomputethe200-th(1000-th,etc)triangularnumber?Exampleproblem:computingtriangularnumbers.(Then-thtriangularnumberisthesumoftheintegersfrom1throughn)InC:3differentstatementsforlooping:for,while,d

7、oExample–200thtriangularnumbern=1triangularNumber=triangularNumber+nn<=200n=n+1yesnotriangularNumber=0PrinttriangularNumberStatementbeforeloopinit_expressionloop_conditionstatementloop_expressionStatementafterloopExample-for/*Programtocalculatethe200thtr

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。