任意整数阶乘的末尾有多少0

任意整数阶乘的末尾有多少0

  • 问题描述
    输入一个正整数n,求n!尾数有多少个0
  • 程序说明
#include <stdio.h>

int main()
{
	int n, tmp, count=0;

	printf("Input n:");
	scanf("%d", &n);
	tmp = n;
	while(n)
	{
		n = n/5;
		count += n;
	}
	printf("The number of 0 in the end of %d! is %d.\n", tmp, count);

	return 0;
}

运行结果

Input n:1000
The number of 0 in the end of 1000! is 249.

猜你喜欢

转载自blog.csdn.net/weixin_41812603/article/details/86594316
今日推荐