求1000阶乘的结果中0的个数(利用数组)

希望能在C中编译通过!注意:不是尾数!
2024-12-21 11:58:13
推荐回答(1个)
回答1:

#include
void main()
{
int a[3000]={1};
int n;
printf(" please input n (1~1000):");
do
{
scanf("%d",&n);
}
while (n>1000||n<0);

int wei=0;
for (int i=2;i<=n;i++)
{
int jinwei=0;
for (int j=0;j<=wei;j++)
{
int w=a[j]*i+jinwei;
a[j]=w%10;
jinwei=w/10;
}
while(jinwei)
{
wei++;
a[wei]=jinwei%10;
jinwei/=10;
}
}
int sum=0;
for (int k=wei;k>=0;k--)
{
printf("%d",a[k]);
if(a[k]==0)sum=sum+1;
}
printf("\n");
printf("%d%s%d\n",n,"!中共有0的个数为:",sum);
}