Python 程式:計算一個數字的階乘中尾隨零的個數
在本文中,我們將瞭解如何解決以下問題陳述。
問題陳述 − 我們得到一個整數 n,我們需要計算階乘中尾隨零的個數。
現在讓我們在下面的實現中觀察解決方案 −
示例
# trailing zero
def find(n):
# Initialize count
count = 0
# update Count
i = 5
while (n / i>= 1):
count += int(n / i)
i *= 5
return int(count)
# Driver program
n = 79
print("Count of trailing 0s "+"in",n,"! is", find(n))輸出
Count of trailing 0s in 79 ! is 18

結論
在本文中,我們已經瞭解如何進行 Python 程式設計來計算一個數字的階乘中尾隨零的個數
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP