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 出阁宴祝福语姐姐简短