n是从8开始,调用cattle(n)就是计算cattle(8);
cattle(8),8>2,返回cattle(7)+cattle(6);结果是cattle(7)+cattle(6)
cattle(7),8大于2,返回cattle(6)+cattle(5);结果是2*cattle(6)+cattle(5)
cattle(6),7大于2,返回cattle(5)+cattle(4);结果是3*cattle(5)+2*cattle(4)
cattle(5),5大于2,返回cattle(4)+cattle(3);结果是5*cattle(4)+3*cattle(3))
cattle(4),4大于2,返回cattle(3)+cattle(2);
结果是8*cattle(3)+5*cattle(2)
cattle(3),3大于2,返回cattle(2)+cattle(1);
结果是13*cattle(2)+8*cattle(1)
cattle(2),是返回1,所以cattle(2)等于1
cattle(1),也是返回1,即cattle(1)等于1
所以结果是13*1+8*1=21.
其实迭代就是要一直就算到能得到值后,在往回计算原来等式的值. |