标签: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