C程序在给定的阶乘中找到尾随零
为了找到给定阶乘中的尾随零,让我们考虑三个示例,如下所述-
示例1
输入-4
输出-0
说明-4!=24,没有尾随零。
因子4!=4x3x2x1=24。没有尾随零,即在0的位置有4个数字。
示例2
输入-6
输出-1
说明-6!=720,一个尾随零。
阶乘6!=6x5x4x3x2x1=720,一个尾随零,因为在0的位置是0数字。
示例3
输入如下-
n = 4 n = 5
输出如下-
没有-4个尾随零!是0
N0-5的尾随零!是1
示例
以下是在给定阶乘中查找尾随零的C程序-
#include输出结果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
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短