为了找到给定阶乘中的尾随零,让我们考虑三个示例,如下所述 -
示例 1
输入 - 4
输出 - 0
说明- 4!= 24,没有尾随零。
因子 4!= 4 x 3 x 2x 1 = 24。没有尾随零,即在 0 的位置有 4 个数字。
示例 2
输入 - 6
输出 - 1
说明- 6!= 720,一个尾随零。
阶乘 6!= 6 x 5 x 4 x 3 x 2 x 1 = 720,一个尾随零,因为在 0 的位置是 0 数字。
示例 3
输入如下 -
n = 4 n = 5
输出如下 -
没有 - 4 个尾随零!是 0
N0 - 5 的尾随零!是 1
以下是在给定阶乘中查找尾随零的 C 程序-
#include <stdio.h> static int trailing_Zeroes(int n){ int number = 0; while (n > 0) { number += n / 5; n /= 5; } return number; } int main(void){ int n; printf("输入整数1:"); scanf("%d",&n); printf("\n no: of trailing zeroe's of factorial %d is %d\n\n ", n, trailing_Zeroes(n)); printf("输入整数2:"); scanf("%d",&n); printf("\n no: of trailing zeroe's of factorial %d is %d ", n, trailing_Zeroes(n)); return 0; }输出结果
执行上述程序时,会产生以下结果 -
输入整数1:5 no: of trailing zeroe's of factorial 5 is 1 输入整数2:6 no: of trailing zeroe's of factorial 6 is 1