Number of trailing zeros in N * ( N | C ++ implementation of the approach ; Function to return the count of trailing 0 s in the given function ; If n is odd ; If n is even ; Find the trailing zeros in n / 2 factorial ; Return the required answer ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findTrailingZeros ( int n ) { if ( n & 1 ) return 0 ; else { int ans = 0 ; n /= 2 ; while ( n ) { ans += n / 5 ; n /= 5 ; } return ans ; } } int main ( ) { int n = 12 ; cout << findTrailingZeros ( n ) ; return 0 ; }