Python 程序计算一个数的阶乘中尾随零的数量

pythonserver side programmingprogramming

在本文中,我们将学习下面给出的问题陈述的解决方案。

问题陈述 − 给定一个整数 n,我们需要计算阶乘中尾随零的数量。

现在让我们观察下面实现中的解决方案 −

示例

# 尾随零
def find(n):
   # 初始化计数
   count = 0
   # 更新计数
   i = 5
   while (n / i>= 1):
      count += int(n / i)
      i *= 5
   return int(count)
# 驱动程序
n = 79
print("Count of trailing 0s "+"in",n,"! is", find(n))

输出

79 中的尾随 0 数!是 18

结论

在本文中,我们了解了如何编写 Python 程序来计算数字阶乘中的尾随零


相关文章