

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Finding trailing zeros of a factorial JavaScript
Given an integer n, we have to write a function that returns the number of trailing zeroes in n!.
For example −
trailingZeroes(4) = 0 trailingZeroes(5) = 1 because 5! = 120 trailingZeroes(6) = 1
Example
const num = 17; const findTrailingZeroes = num => { let cur = 5, total = 0; while (cur <= num) { total += Math.floor(num / cur); cur *= 5; }; return total; }; console.log(findTrailingZeroes(num)); console.log(findTrailingZeroes(5)); console.log(findTrailingZeroes(1));
Output
And the output in the console will be −
3 1 0
- Related Questions & Answers
- Count trailing zeros in factorial of a number in C++
- Program to find trailing zeros in factorial of n in C++?\n
- Factorial Trailing Zeroes in C++
- Add trailing Zeros to a Python string
- Python Program to Count trailing zeroes in factorial of a number
- Java Program to Count trailing zeroes in factorial of a number
- Remove Trailing Zeros from string in C++
- C/C++ Program to Count trailing zeroes in factorial of a number?
- C/C++ Programming to Count trailing zeroes in factorial of a number?
- Count number of trailing zeros in product of array in C++
- C program to find trailing zero in given factorial
- Count number of trailing zeros in Binary representation of a number using Bitset in C++
- C Program to count trailing and leading zeros in a binary number
- Remove trailing zeros in decimal value with changing length in MySQL?
- Maximum number of trailing zeros in the product of the subsets of size k in C++
Advertisements