ALGORITHMS FLOWCHARTING II.ppt
《ALGORITHMS FLOWCHARTING II.ppt》由会员分享,可在线阅读,更多相关《ALGORITHMS FLOWCHARTING II.ppt(20页珍藏版)》请在麦多课文档分享上搜索。
1、ALGORITHMS & FLOWCHARTING II,LOOPS,Computers are particularly well suited to applications in which operations are repeated many times. If the same task is repeated over and over again a loop can be used to reduce program size and complexity,Example 8: Write an algorithm and draw a flowchart to calcu
2、late 24 .,Algorithm: Step 1: Base 2 Step 2: Product Base Step 3: Product Product * Base Step 4: Product Product * Base Step 5: Product Product * Base Step 6: Print Product,Flowchart,Question: What happens if you want to calculate 2 to the power of 1000? Answer: Use a LOOP (repeated execution of the
3、same set of instructions),Example 9: Write an algorithm and draw a flowchart to calculate 24 using a loop approach? Verify your result by a trace table.,Algorithm:,Step 1: Base 2 Step 2: Power 4 Step 3: Product Base Step 4: Counter 1 Step 5: While Counter PowerRepeat Step 5 through step 7 Step 6: Pr
4、oduct Product * Base Step 7: Counter Counter +1 Step 8: Print Product,TRACING,Example 10: Write down an algorithm and draw a flowchart to find and print the largest of three numbers. Read numbers one by one. Verify your result by a trace table. (Use 5, 7, 3 as the numbers read),Algorithm,Step 1: Inp
5、ut N1 Step 2: Max N1 Step 3: Input N2 Step 4: If (N2Max) thenMax = N2endif Step 5: Input N3 Step 6: If (N3Max) then Max = N3endif Step 7: Print “The largest number is:”,Max,Flowchart & Tracing,N1 N2 N3 Max N2Max N3Max Step1: 5 ? ? ? ? ? Step 2: 5 ? ? 5 ? ? Step 3: 5 7 ? 5 T ? Step 4: 5 7 ? 7 T ? Ste
6、p 5: 5 7 3 7 F F Step 6: 5 7 3 7 F F Step 8: Print Largest Number is 7,Example 11: Write down an algorithm and draw a flowchart to find and print the largest of N (N can be any number) numbers. Read numbers one by one. Verify your result by a trace table. (Assume N to be 5 and the following set to b
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ALGORITHMSFLOWCHARTINGIIPPT
