Skip to content

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

@shailbenq

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

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