Trailing Zeros in Factorial Python

PROGRAM TO COUNT TRAILING ZEROS IN FACTORIAL OF A NUMBER


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 = 100
print("Count of trailing 0s " +
"in 100! is",findTrailingZeros(n))

OUTPUT
Count of trailing 0s in 100! is 24 

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java