I'm trying to count the number of trailing zero with a factorial.
e.g
4! = 24 So you retrieve 0.
9! = 362880 So you retrieve 1.
10! = 9! x 10 = 3628800 So you retrieve 2.
11! = 10! x 11 = 3.99168E7 So you retrieve 2.
static double factorial(double n) {
double f = 1;
for(int i = 1 ; i <= n ; i++) {
f *= i;
}
return f;
}
static int numberOfZeros(double f) {
int ten = 1;
int count = 0;
for(;f%Math.pow(10, ten) == 0;count++) {
ten++;
}
return count;
}
this codes are Okay until number n is 22. but when i try to put 23 into then count is 0. Of course, mathematically 23! has trailing zeros.