Number of zeroes at the end of a factorial I was working with this problem, which is to find the number of zeros at the end of any factorial.

Here's my solution:

#include&lt;bits/stdc++.h&gt;
using namespace std;
int main(){

    int numCases,num,zeroCount=0,mulFive,temp,i=0;
    cout&lt;&lt;numeric_limits&lt;int&gt;::max()-1000000000&lt;&lt;endl;
    cin&gt;&gt;numCases;
    int solutionArray[numCases];
    temp=numCases;
    while(numCases--)
    {
         zeroCount=0;
         cin&gt;&gt;num;
         mulFive=5;
         while(num/mulFive!=0)
         {
             zeroCount=zeroCount+ (num/mulFive);
             mulFive=mulFive*5;
         }
         solutionArray[i]=zeroCount;
         i++;
         //cout&lt;&lt;zeroCount;
    }
    for(int k=0;k&lt;temp;k++)
        cout&lt;&lt;solutionArray[k]&lt;&lt;endl;

    return 0;
}


This is the most basic code that I could come up with. How should I make it more efficient using the same logic?  Perhaps I should use different logic?
There is a problem with your solution for large numbers ( >= 5^13 to be exact) because mulFive=mulFive*5; will go negative as the int overflows. 

To protect against this, you could do 

 while(num/5!=0)
 {
     zeroCount=zeroCount+ (num/5);
     num = num/5;
 }


i.e. divide the number rather than multiply the divisor, then only the size of num is a limit (2^31-1)