Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

number of trailing zeros in a factorial of a number.

# 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 "
Number of trailing zeros = ", zeros(30);  # 7
 
PREVIOUS NEXT
Tagged: #number #trailing #zeros #factorial
ADD COMMENT
Topic
Name
8+1 =