书签 分享 收藏 举报 版权申诉 / 38
上传文档赚钱

类型C语言学习第二章(英文版)课件.ppt

  • 上传人(卖家):晟晟文业
  • 文档编号:5203610
  • 上传时间:2023-02-17
  • 格式:PPT
  • 页数:38
  • 大小:200KB
  • 【下载声明】
    1. 本站全部试题类文档,若标题没写含答案,则无答案;标题注明含答案的文档,主观题也可能无答案。请谨慎下单,一旦售出,不予退换。
    2. 本站全部PPT文档均不含视频和音频,PPT中出现的音频或视频标识(或文字)仅表示流程,实际无音频或视频文件。请谨慎下单,一旦售出,不予退换。
    3. 本页资料《C语言学习第二章(英文版)课件.ppt》由用户(晟晟文业)主动上传,其收益全归该用户。163文库仅提供信息存储空间,仅对该用户上传内容的表现方式做保护处理,对上传内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知163文库(点击联系客服),我们立即给予删除!
    4. 请根据预览情况,自愿下载本文。本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
    5. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007及以上版本和PDF阅读器,压缩文件请下载最新的WinRAR软件解压。
    配套讲稿:

    如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。

    特殊限制:

    部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。

    关 键  词:
    语言 学习 第二 英文 课件
    资源描述:

    1、The number of the group:The number of the group:7716202377162023Chapter 2 Chapter 2 Algorithm and FlowchartAlgorithm and Flowchartn2.1 What is algorithmn2.2 Features of algorithmsn2.3 Pseudocoden2.4 Flowchartn2.5 Control Structuresn2.6 Selection Structuren2.7 Repetition StructureOutlineOutlineKey po

    2、intsKey pointsnWhat is algorithmnFeatures of algorithmsnFlowchart2.2.1 What is algorithm1 What is algorithmnBefore writing a program:nHave a thorough understanding of the problem nCarefully plan an approach for solving itnWhile writing a program:nKnow what”building blocks”are availablenUse good prog

    3、ramming principles2.2.1 What is algorithm1 What is algorithm A step-by-step problem-solving procedure,especially an established,recursive computational procedure for solving a problem in a finite number of steps.2.2.2 Features of algorithm2 Features of algorithmnDeterminismnAn algorithm is determini

    4、stic,if at any stage of the algorithm execution,the next action step is clearly defined.nFinitenessnThe finiteness restricts the definition of the algorithm to a finite long-term operation.nEffectivenessnThe effect of each statement of an algorithm must be clearly defined.2.2.3 Pseudocode3 Pseudocod

    5、enPseudocodenArtificial,informal language that helps us develop algorithmsnSimilar to everyday EnglishnNot actually executed on computers nHelps us“think out”a program before writing it nEasy to convert into a corresponding C programnConsists only of executable statements2.2.3 Pseudocode3 Pseudocode

    6、nExample of pseudocode nIf students grade is greater than or equal to 60 Print“Passed”nIf students grade is greater than or equal to 60 Print“Passed”else Print“Failed”2.2.4 Flowchart4 FlowchartnFlowchart nGraphical representation of an algorithmnDrawn using certain special-purpose symbols connected

    7、by arrows called flowlinesnRectangle symbol(action symbol):nIndicates any type of actionnOval symbol:nIndicates the beginning or end of a program or a section of codenSingle-entry/single-exit control structures nConnect exit point of one control structure to entry point of the next(control-structure

    8、 stacking)nMakes programs easy to build2.2.5 Control Structures5 Control StructuresnSequential execution nStatements executed one after the other in the order writtennTransfer of controlnWhen the next statement executed is not the next one in sequencenOveruse of goto statements led to many problemsn

    9、 Bohm and JacopininAll programs written in terms of 3 control structuresnSequence structures:Built into C.Programs executed sequentially by defaultnSelection structures:C has three types:if,if/else,and switch(book chapter 4)nRepetition structures:C has three types:while,do/while and forn Single-entr

    10、y/single-exit control structures nConnect exit point of one control structure to entry point of the next(control-structure stacking)nMakes programs easy to build2.2.5 Control Structures5 Control Structures2.2.6 Selection Structure(if)6 Selection Structure(if)nSelection structure:nUsed to choose amon

    11、g alternative courses of actionnPseudocode:nIf students grade is greater than or equal to 60Print“Passed”nIf condition true nPrint statement executed and program goes on to next statementnIf false,print statement is ignored and the program goes onto the next statementnIndenting makes programs easier

    12、 to readnC ignores whitespace characters2.2.6 Selection Structure(if)6 Selection Structure(if)nPseudocode statement in C:if(grade=60)printf(Passedn);nC code corresponds closely to the pseudocodenDiamond symbol(decision symbol)nIndicates decision is to be madenContains an expression that can be true

    13、or falsenTest the condition,follow appropriate path2.2.6 Selection Structure(if)6 Selection Structure(if)nif structure is a single-entry/single-exit structureyesnograde=60print“Passed”A decision can be made on any expression.zero-no nonzero-yesExample:3-4 is yes2.2.6 Selection Structure(if)6 Selecti

    14、on Structure(if)n Page 32 nIf you type a number less than 10,you get a message“What an obedient servant you are!”on the screen.nOtherwise,the program doesnt do anything.STARTPRINT enter a num less than 10 INPUT num is num=60)printf(Passedn);else printf(Failedn);nConditional operator(?:)nTakes three

    15、arguments(condition,value if true,value if false)nOur pseudocode could be written:printf(%sn,grade=60?Passed:Failed);nOr it could have been written:grade=60?printf(“Passedn”):printf(“Failedn”);2.2.6 Selection Structure(if/else)6 Selection Structure(if/else)nFlow chart of the if/else selection struct

    16、urenNested if/else structures nTest for multiple cases by placing if/else selection structures inside if/else selection structuresnOnce condition is met,rest of statements skippednDeep indentation usually not used in practiceyesnoprint“Failed”print“Passed”grade=602.2.6 Selection Structure(if/else)6

    17、Selection Structure(if/else)nPseudocode for a nested if/else structureIf students grade is greater than or equal to 90 Print“A”else If students grade is greater than or equal to 80 Print“B”else If students grade is greater than or equal to 70 Print“C”else If students grade is greater than or equal t

    18、o 60 Print“D”else Print“F”2.2.6 Selection Structure(if/else)6 Selection Structure(if/else)nCompound statement:nSet of statements within a pair of bracesnExample:if(grade=60)printf(Passed.n);else printf(Failed.n);printf(You must take this course again.n);nWithout the braces,the statementprintf(You mu

    19、st take this course again.n);would be executed automatically2.2.6 Selection Structure(if/else)6 Selection Structure(if/else)nBlock:nCompound statements with declarationsnSyntax errorsnCaught by compilernLogic errors:nHave their effect at execution timenNon-fatal:program runs,but has incorrect output

    20、nFatal:program exits prematurely2.2.6 Selection Structure(switch)6 Selection Structure(switch)nswitch(switch-case-default)allows us to make a decision from a number of choices.nThe switch statement most often appears as follows:switch(integer expression)case constant1:do this;case constant2:do this;

    21、case constant3:do this;default:do this;2.2.6 Selection Structure(switch)6 Selection Structure(switch)nswitch(choice)case 1:statement1;break;case 2:statement2;break;case 3:statement3;break;case 4:statement4;break;/*in Page 86 of the textbook*/STARTcase 1case 2case 3case 4nonononoyesyesyesyesstatement

    22、1statement2statement3statement4 STOP2.2.7 Repetition Structure(while)7 Repetition Structure(while)nRepetition structurenProgrammer specifies an action to be repeated while some condition remains truenPsuedocode:While there are more items on my shopping list Purchase next item and cross it off my lis

    23、t nwhile loop repeated until condition becomes false 2.2.7 Repetition Structure(while)7 Repetition Structure(while)nExample:int product=2;while(product=1000)product=2*product;product=1000product=2*product yesno2.2.7 Repetition Structure(for)7 Repetition Structure(for)nThe for is probably the most po

    24、pular looping instruction in C.nThe for allows us to specify three things in a loopnSetting a loop counter to an initial valuenTesting whether the loop counter reaches the desired number nIncreasing the value of loop counter2.2.7 Repetition Structure(for)7 Repetition Structure(for)nThe general form

    25、of the for loop:for(initialise counter;test;increment)body of the loop;2.2.7 Repetition Structure(for)7 Repetition Structure(for)nThe flowchart of the for loop:initialise START test STOP False True body of loop increment2.2.7 Repetition Structure(for)7 Repetition Structure(for)nExample program(Page

    26、67)#include void main()int p,n,count;float r,si;for(count=1;count=3;count=count+1)printf(”Enter Values of p,n and r”);scanf(”%d%d%f”,&p,&n,&r);si=p*n*r/100;printf(”Simple Interest=Rs.%fn”,si);2.2.7 Repetition Structure(for)7 Repetition Structure(for)nFlowchart of the program START count=1count=count

    27、+1 iscount=3 STOPNoYesINPUT p,n,r si=p*n*r/100PRINT si2.2.7 Repetition Structure(for)7 Repetition Structure(for)nThe for statement gets executed as follows:nThe value of count is set to an initial value 1.nThe condition count=3 is tested.The body of the loop is executed for the first time.nUpon reac

    28、hing the closing brace of for,control is sent back to for,the value of count gets incremented by 1.nAgain the test count=3 is performed.nThe body of the loop continues to get executed till count doesnt exceed the value 3.nWhen count reaches 4,the control exits from the loop and transferred to the ne

    29、xt statement.SummarySummarynAn algorithm is a step-by-step problem-solving procedure in a finite number of steps.nThe features of algorithm are determinism,finiteness and effectiveness.nFlowchart is a graphical representation of an algorithm.nC has three types of selection structures:if,if/else,and

    30、switch.nC has three types of repetition structures:while,do/while and for.AssignmentAssignmentnRepresent the following Pseudocode as a flowchart.If students grade is greater than or equal to 90 Print“A”else If students grade is greater than or equal to 80 Print“B”else If students grade is greater th

    31、an or equal to 70 Print“C”else If students grade is greater than or equal to 60 Print“D”else Print“F”AssignmentAssignmentnInput three integers,find out and output the maximum.Please present the algorithm of this problem,and describe it by flowchart.nInput the ages of ten students one by one,calculat

    32、e the average age of them and output the average age finally.Please present the algorithm of this problem,and describe it by flowchart.nInput the ages of ten students one by one,find out the minimum age of them and output it finally.Please present the algorithm of this problem,and describe it by flowchart.Thank you!Thank you!See you next time!

    展开阅读全文
    提示  163文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
    关于本文
    本文标题:C语言学习第二章(英文版)课件.ppt
    链接地址:https://www.163wenku.com/p-5203610.html

    Copyright@ 2017-2037 Www.163WenKu.Com  网站版权所有  |  资源地图   
    IPC备案号:蜀ICP备2021032737号  | 川公网安备 51099002000191号


    侵权投诉QQ:3464097650  资料上传QQ:3464097650
       


    【声明】本站为“文档C2C交易模式”,即用户上传的文档直接卖给(下载)用户,本站只是网络空间服务平台,本站所有原创文档下载所得归上传人所有,如您发现上传作品侵犯了您的版权,请立刻联系我们并提供证据,我们将在3个工作日内予以改正。

    163文库