Answers for "find the trailing zeros of the factorial value of the given number"

0

trailing zeroes in factorial

#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int res=0;
        for(int i=5;i<=n;i=i*5)
        {
            res=res+n/i;
        }
        cout<<res<<endl;
    }
    return 0;
}
Posted by: Guest on June-08-2021
0

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 "\nNumber of trailing zeros = ", zeros(30);  # 7
Posted by: Guest on September-12-2021

Code answers related to "find the trailing zeros of the factorial value of the given number"

Python Answers by Framework

Browse Popular Code Answers by Language