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<bits/stdc++.h>
using namespace std;
int main(){
int numCases,num,zeroCount=0,mulFive,temp,i=0;
cout<<numeric_limits<int>::max()-1000000000<<endl;
cin>>numCases;
int solutionArray[numCases];
temp=numCases;
while(numCases--)
{
zeroCount=0;
cin>>num;
mulFive=5;
while(num/mulFive!=0)
{
zeroCount=zeroCount+ (num/mulFive);
mulFive=mulFive*5;
}
solutionArray[i]=zeroCount;
i++;
//cout<<zeroCount;
}
for(int k=0;k<temp;k++)
cout<<solutionArray[k]<<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?