📜  数字的阶乘中尾随零的数量. - 红宝石代码示例

📅  最后修改于: 2022-03-11 15:04:46.105000             🧑  作者: Mango

代码示例1
# Number of trailing zeros in a factorial of a number

def zeros(n)
  zeros = 0
  while (n > 0) 
    n = (n / 5).floor
    zeros += n
  end
  zeros  
end

print "Number of trailing zeros = ", zeros(6);   # 1
print "\nNumber of trailing zeros = ", zeros(30);  # 7