论文部分内容阅读
五、此题是用计算机模拟一个物理事件的题,即模拟人上楼梯的过程。楼梯最多有9阶,那么上楼梯至多迈9步,可用9重循环模拟上楼过程,每重循环代表1步,1步可迈1阶或2阶,那么每重循环取值范围为1~2。用变量 S 存放上楼的方案数,即何时各步所迈台阶数之和与总阶数相等时即为一种上楼方案。这时打印该方案,并打印每一步所迈台阶数,循环搜索完毕,打印总方案数。程序及运行结果如下:
Fifth, this question is a computer simulation of a physical event, that is, the process of simulating people on the stairs. Stairs have up to 9 steps. Then up stairs take up to 9 steps. You can use 9-cycle simulation to go upstairs process. Each cycle represents 1 step, 1 step can be 1 or 2 steps, then the value of each cycle is from 1 to 2. The variable S is used to store the number of plans for the upper floors, that is, when the sum of the number of step steps at each step is equal to the total order, it is a plan for going upstairs. At this time, the program is printed, and the number of steps is printed for each step. After the loop search is completed, the total number of printouts is printed. The procedures and results of the operation are as follows: