Write a JavaScript program to find the number of trailing zeros in the decimal representation of the factorial of a given number

  • برمجة جافاسكربت java script
  • برمجة

Write a JavaScript program to find the number of trailing zeros in the decimal representation of the factorial of a given number

الأجوبة

function trailing_zeros_factorial(n) {
    var result = 0;
    for (var i = 5; i <= n; i += 5) {
        var num = i;
        while (num % 5 === 0) {
            num /= 5;
            result++;
        }
    }
    return result;
}

console.log(trailing_zeros_factorial(8))
console.log(trailing_zeros_factorial(9))
console.log(trailing_zeros_factorial(10))
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...