C语言编程学习课件 (38).pdf
《C语言编程学习课件 (38).pdf》由会员分享,可在线阅读,更多相关《C语言编程学习课件 (38).pdf(16页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Programming In CProgramming In C deeper and deeper deeper and deeper into the dreaminto the dream “Recursion is nesting,all kinds of nesting.(Story in story,movie in movie,picture in picture,etc.)”Step 1:move the smallest plate 3 from tower A to tower C Step 2:move the second smallest plate 2 from t
2、ower A to tower B Step 3:move plate 3 from tower C to tower B Programming In CProgramming In C void hanoi(int n,char A,char B,char C)if(n=1)move(A,C);/recursive exits/recursive exits else /three Steps/three Steps hanoi(n-1,A,C,B);/Recursive reduction/Recursive reduction move(A,C);hanoi(n-1,B,A,C);/R
3、ecursive reduction/Recursive reduction Programming In CProgramming In C void move(char get,char put)printf(%c-%cn,get,put);void main()int n;printf(input the number of diskes:n);scanf(%d,&n);printf(The step to moving%d diskes:n,n);hanoi(n,A,B,C);Programming In CProgramming In C Programming In CProgra
4、mming In C If the number of plates is 10,it needs to be moved 1023 times.When the number of plates is 64,it needs to be moved about 184.4 billion times.If each move takes 1 microsecond,it will take 600,000 years to complete the operation.However,the Hanoi()function can achieve such complicated opera
5、tions in less than 10 lines of code.How simple and efficient it is!Programming In CProgramming In C In mathematics and computer science,recursion refers to a method of using the function itself in the definition of the function.A prerequisite that a problem can be a recursive problem is:The latter p
6、art is similar to the original question,and the latter part is a simplification of the original question.A recursive function must contain two basic elements:First,there must be iterative processes(to call itself),Second,there must be conditions to jump out of the iterative process(to set up recursi
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C语言编程学习课件 38 语言 编程 学习 课件 38
限制150内