首页 > 代码库 > C 数组模拟阶乘运算

C 数组模拟阶乘运算

#include <stdio.h>void rdump(int arr[],int len){    int i = 0;    for(i=len-1;i >= 0; --i)    {        printf("%d",arr[i]);    }    printf("\n");}void trailingZeroes(int n) {    int arr[10000] = {1},len = 1,i = 0,j = 0,c = 0,d = 0;    for(i=2; i <= n; ++i)    {        for(j = 0; j < len; ++j)        {            d = arr[j] * i + c;            arr[j] = d % 10;            c = d / 10;        }        for(; c > 0; c /= 10)        {            arr[len++] = c % 10;        }    }    rdump(arr,len);}int main(){    int n = 0;    while(1)    {        scanf("%d",&n);        trailingZeroes(n);    }    return 0;}

 

C 数组模拟阶乘运算