1 / 10

例题 1 : 1*2*3*…*10=?

例题. 例题 1 : 1*2*3*…*10=?. 执行语句. 是否符合条件. 是. 否. 结束. 循环结构. 例题 1 : 1*2*3*…*10=?. 初始化: i:=1,sum:=1;. 步骤: ( 1 )当 i=1 时, sum:=sum*I 得 sum:=1 ( 2 )当 i=2 时, sum:=sum*i 得 sum:=2 ( 3 )当 i=3 时, sum:=sum*i 得 sum:=6 ( 4 )当 i=4 时, sum:=sum*i 得 sum:=24 …… (10) 当 i=10 时, sum:=sum*I

jett
Download Presentation

例题 1 : 1*2*3*…*10=?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 例题 • 例题1:1*2*3*…*10=?

  2. 执行语句 是否符合条件 是 否 结束 循环结构

  3. 例题1:1*2*3*…*10=? 初始化: i:=1,sum:=1; 步骤: (1)当i=1时,sum:=sum*I 得sum:=1 (2)当i=2时,sum:=sum*i 得sum:=2 (3)当i=3时,sum:=sum*i 得sum:=6 (4)当i=4时,sum:=sum*i 得sum:=24 …… (10)当i=10时,sum:=sum*I …… sum:=sum*i i:=i+1; i<=10 ? 是 否 结束

  4. For循环 • 格式: • for 条件1 to 条件2 do • begin • 执行语句; • end; • 注意:条件1<=条件2

  5. 例题1:1*2*3*…*10=? • Program e1; • Var i,sum:longint; • Begin • i:=1; • sum:=1 • for i to 10 do • begin • sum:=sum*i • end; • writeln(sum) • end. For 循环

  6. While循环 • 格式: • while 条件 do • begin • 语句; • end

  7. 例题1:1*2*3*…*10=? • Program e1; • Var i,sum:longint; • Begin • i:=1; • sum:=1 • while i<=10 do • begin • sum:=sum*I; • i:=i+1 • end; • writeln(sum) • end.

  8. Repeat…until • 格式: • Repeat • 语句;… • Until 条件;

  9. 例题1:1*2*3*…*10=?

  10. 作业 • 编写程序计算下面式子的结果; • 1*2+2*3+3*4+…+20*21=?

More Related