Skip to content

Commit f1e0826

Browse files
Simplified code function is added
1 parent a6cf18b commit f1e0826

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
package NumberBasedProblems;
22

33
public class TailorZero {
4+
5+
static int findTrailingZeros(int n)
6+
{
7+
if (n < 0) // Negative Number Edge Case
8+
return -1;
9+
10+
// Initialize result
11+
int count = 0;
12+
13+
// Keep dividing n by powers
14+
// of 5 and update count
15+
for (int i = 5; n / i >= 1; i *= 5)
16+
count += n / i;
17+
18+
return count;
19+
}
20+
421
public static void main(String[] args) {
522
long n=201,sum=1,count=0;
623
for(long i=2;i<=n;i++)
724
sum*=i;
8-
System.out.println(sum);
25+
System.out.println("Factorial = "+sum);
926
while(sum!=0){
1027
long rem=sum%10;
1128
if(rem!=0)
1229
break;
1330
count++;
1431
sum/=10;
1532
}
16-
System.out.println(count);
33+
System.out.println("trailing zero count = "+count);
1734
}
1835
}
1936

0 commit comments

Comments
 (0)