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;
}

 

posted @ 2016-09-22 22:48  你好阿汤哥  Views(437)  Comments(0Edit  收藏  举报