Answers for "trailing zeros in factorial python"

1

number of trailing zeros in factorial python

def findTrailingZeros(n):
 
    # Initialize result
    count = 0
 
    # Keep dividing n by
    # 5 & update Count
    while(n >= 5):
        n //= 5
        count += n
 
    return count
 
 
# Driver program
n = 100
print("Count of trailing 0s " +
      "in 100! is", findTrailingZeros(n))
Posted by: Guest on May-28-2021
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

Code answers related to "trailing zeros in factorial python"

Python Answers by Framework

Browse Popular Code Answers by Language