(4.5)--4.5Iterativealgorithmandforstate.pdf
《(4.5)--4.5Iterativealgorithmandforstate.pdf》由会员分享,可在线阅读,更多相关《(4.5)--4.5Iterativealgorithmandforstate.pdf(10页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Iterative algorithm and for statement implementationIterative algorithm and for statement implementation4.5For many problems,a set of steps need to be performed repeatedly until achieving a certain situation.For example,design an algorithm for calculating the sum of 15.Iterative algorithm and for st
2、atement implementation4.5A simple algorithm could be designed as following:Step 1:Initialize sum to 0;Step 2:Add 1 to sum;Step 3:Add 2 to sum;Step 4:Add 3 to sum;Step 5:Add 4 to sum;Step 6:Add 5 to sum;Step 7:Output sum,which stores the sum from 1 to 5;Iterative algorithm and for statement implement
3、ation4.5With the above algorithm,100000 lines of operations like Add 1 to sum should be added.Obviously,this will not work when we need to deal with large-scale problems.A potential issue in this algorithm designIf the problem is to calculate the sum of 1100000,how should we design the algorithm?Ite
4、rative algorithm and for statement implementation4.5The iterative algorithm uses the idea of iteration,which is often adopted incomputational thinking.The repeated steps in an algorithm can be describedsimply and clearly,so that shorten the algorithm and improve its readability.To design an iterativ
5、e algorithm,first we should determine the operation or a setof operations that need to be repeatedly performed,and then determine how manytimes they need to be performed.Iterative algorithmIterative algorithm and for statement implementation4.5For the problem we just mentioned,a shorter iterative al
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 4.5 Iterativealgorithmandforstate
限制150内