You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi I checked the solution provided for number problem to find no of trailing zeroes in a factorial of a number. Your solution does not consider the case where number is larger than 25. If its larger than 25, the number of trailing zeroes will be number/5 + 1. In your case 26! will have 5 trailing zeroes but actually it should be 6. This is also true for multiples of 25 ,125,625, So below is one of the approach to solve this issue. Thanks :)
public class FactorialNoOfTrailingZeroes {
public static int findTrailingZeroes(int number) {
int res=0;
int i = 1;
while(number >= Math.pow(5, i)){
res += number/Math.pow(5, i);
i++;
}
return res;
}
public static void main(String[] args) {
System.out.println(findTrailingZeroes(60));
}
}
The text was updated successfully, but these errors were encountered:
Hi I checked the solution provided for number problem to find no of trailing zeroes in a factorial of a number. Your solution does not consider the case where number is larger than 25. If its larger than 25, the number of trailing zeroes will be number/5 + 1. In your case 26! will have 5 trailing zeroes but actually it should be 6. This is also true for multiples of 25 ,125,625, So below is one of the approach to solve this issue. Thanks :)
The text was updated successfully, but these errors were encountered: