<script type="text/vbs">
function test(n)
if n=1 then test=1:exit function
test=test(n-1)*n
end function
alert(test(3))
alert(test(4))
alert(test(5))
</script>
test(3)
↓
test(2)*3
↓
test(1)*2
因为test(1)=1 所以从后面往前面归.test(1)*2*3=6
test(4)
↓
test(3)*4
↓
test(2)*3
↓
test(1)*2
因为test(1)=1 所以从后面往前面归.test(1)*2*3*4=24
test(5)
↓
test(4)*5
↓
test(3)*4
↓
test(2)*3
↓
test(1)*2
因为test(1)=1 所以从后面往前面归.test(1)*2*3*4*5=120
博客展示了一段VBScript代码,定义了一个递归函数test用于计算阶乘。通过代码示例,详细说明了test(3)、test(4)和test(5)的递归计算过程,从test(1)开始逐步往前归,得出相应阶乘结果。
1217

被折叠的 条评论
为什么被折叠?



