任意正整数求阶乘

mac2022-06-30  142

# 题目:利用递归方法求任意输入的正整数阶乘。 from pip._vendor.distlib.compat import raw_input #阶乘方法 def fact(j): total = 0 if j == 0: total = 1 else: total = j * fact(j - 1) return total n = int(raw_input("请输入一个正整数:")) for i in range(1,n+1): # 此处输出当前输入整数之前包括本身在内的所有正整数的阶乘 print ('%d! = %d' % (i,fact(i))) #此处仅输出输入正整数阶乘 if i == n: print('%d! = %d' % (i, fact(i)))

转载于:https://www.cnblogs.com/bilaisheng/p/10211057.html

相关资源:java 求任意一个正数的阶乘
最新回复(0)