Whats wrong with my code...works fine with numbers like 5,24,25,50,100 but fails with 9247


#1

for A = 9247
my code gives 3183
and answer is supposed to be 2307 according to solution

int Solution::trailingZeroes(int A) {
int ans = 0;
for(int i = 5; i<=A; i +=5)
{
int temp = i;
while(temp>=5)
{
if(temp % 5 == 0)
ans++;
temp = temp/5;
}
}
return ans;
}


#2

You’re dividing by 5 irrespective of the result of the modulus operation. If it is not a multiple of 5, it may become one when you do integer division.