码迷,mamicode.com
首页 > 其他好文 > 详细

大数阶乘(结果)

时间:2018-08-05 22:37:35      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:define   style   char   for   factor   span   大数阶乘   factorial   temp   

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MaxSize 1000000

char *BigNumFactorial(int InputOrderMultiplier)
{
    int *TempResult = malloc(MaxSize*sizeof(int));
    int TempResultEnd;
    memset(TempResult,0,MaxSize*sizeof(int));
    TempResult[0] = 1;
    
    char *Result = malloc(MaxSize*sizeof(char));
    memset(Result,0,MaxSize*sizeof(char));
    int ResultEnd = 0;
    
    int Carry = 0,Digit = 1;
    int TripNum,TripDigit;
    int Temp;
    
    for(TripNum = 2;TripNum <= InputOrderMultiplier;TripNum ++)
    {
        Carry = 0;
        for(TripDigit = 0;TripDigit < Digit;TripDigit ++)
        {
            //multiply every TR‘s TD by TN
            Temp = TempResult[TripDigit]*TripNum + Carry;
            TempResult[TripDigit] = Temp % 10;
            Carry = Temp / 10;
        }
        while(Carry)
        {
            TempResult[Digit++] = Carry % 10;
            Carry /= 10;
        }
    }
    
    for(TempResultEnd = Digit-1;TempResultEnd >= 0;TempResultEnd --)
    {
        Result[ResultEnd++] = TempResult[TempResultEnd] + 0;
    }
    Result[ResultEnd] = \0;
    return Result;
}

int main()
{
    int InputOrderMultiplier = 19999;
    char *Result = BigNumFactorial(InputOrderMultiplier);
    puts(Result);
    return 0;
}

 

大数阶乘(结果)

标签:define   style   char   for   factor   span   大数阶乘   factorial   temp   

原文地址:https://www.cnblogs.com/Asurudo/p/9427288.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!