Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correction for problem: Find no of trailing zeroes. #3

Open
shailbenq opened this issue Apr 9, 2014 · 1 comment
Open

Correction for problem: Find no of trailing zeroes. #3

shailbenq opened this issue Apr 9, 2014 · 1 comment

Comments

@shailbenq
Copy link

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));
   }
}
@techpanja
Copy link
Owner

thanks for the comment.. i will update it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants