the number of trailing zeros in a factorial of a given number - Ruby

后端 未结 12 1947
执念已碎
执念已碎 2020-12-11 03:37

Having a little trouble trying calculate the number of trailing zeros in a factorial of a given number. This is one of the challenges from Codewars- can\'t get mine to pass.

12条回答
  •  无人及你
    2020-12-11 04:20

    n = int (raw_input())
    count = 0
    num = 1
    for i in xrange(n+1):
            if i != 0:
                num = num * i
    
    while(num >= 10):
    
        if num%10 == 0:
           count+=1
           num = num/10
        else:
            break
    
    print count
    

提交回复
热议问题