-
Notifications
You must be signed in to change notification settings - Fork 89
Open
Description
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));
}
}
Metadata
Metadata
Assignees
Labels
No labels