Trailing Zeros in Factorial Python
PROGRAM TO COUNT TRAILING ZEROS IN FACTORIAL OF A NUMBER
OUTPUT
Count of trailing 0s in 100! is 24
def findTrailingZeros(n): # Initialize result count = 0 # Keep dividing n by # powers of 5 and # update Count i=5 while (n/i>=1): count += int(n/i) i *= 5 return int(count) # Driver program n = 100print("Count of trailing 0s " + "in 100! is",findTrailingZeros(n))
Count of trailing 0s in 100! is 24
Comments
Post a Comment