Can anyone please tell me what's wrong with this solution?


#1
int Solution::trailingZeroes(int A) {
long long int sum=24;
int n0=0;
for(int i=5;i<=A;i++){
    sum*=i;
    while(sum%0==0){
        n0++;
        sum/=10;
    }
    sum=sum%10;
    //sum*=10;
}
return n0;

}

it gives me Floating point exception error, but I think this is a more understandable solution…


#2

You just need to do this!

int Solution::trailingZeroes(int A) 
{ 
    return (A==0) ? 0 : (A/5)+trailingZeroes(A/5); 
}

#3
  1. int Solution::trailingZeroes(int A) {
    
  2. 	long long int sum=24;
    
  3. 	int n0=0;
    
  4. 	for(int i=5;i<=A;i++){
    
  5. 	    sum*=i;
    
  6. 	    while(sum%0==0){
    
  7. 	        n0++;
    
  8. 	        sum/=10;
    
  9. 	    }
    
  10. 	    sum=sum%10;
    
  11. 	    //sum*=10;
    
  12. 	}
    
  13. 	return n0;
    
  14. }
    

In line 6 modulo operation by 0 gives that error.