Skip to content

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

Description

@shailbenq

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));
   }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions