Trailing number of 0 s in product of two factorials | CPP program for count number of trailing zeros in N ! * M ! ; Returns number of zeros in factorial n ; dividing x by powers of 5 and update count ; Returns count of trailing zeros in M ! x N ! ; Driver program
#include <iostream> NEW_LINE using namespace std ; int trailingZero ( int x ) { int i = 5 , count = 0 ; while ( x > i ) { count = count + x / i ; i = i * 5 ; } return count ; } int countProductTrailing ( int M , int N ) { return trailingZero ( N ) + trailingZero ( M ) ; } int main ( ) { int N = 67 , M = 98 ; cout << countProductTrailing ( N , M ) ; return 0 ; }