File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change 11package NumberBasedProblems ;
22
33public 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
You can’t perform that action at this time.
0 commit comments