大數階乘

/*
  Description:大數階乘 n!
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX_SIZE 100024

int ans[MAX_SIZE+10];

void Multiply(int n)
{
    int i, move = 0;
    for(i = 0; i < MAX_SIZE; ++i){
       ans[i] = ans[i]*n + move;
       if(ans[i] >= 10){
           move = ans[i]/10;
           ans[i] %= 10;
           //printf("move = %d\n", move);
       }
       else move = 0;
      
    }
}

void Print(int a[])
{
    int isPrint = 0;
    int i;
    for(i = MAX_SIZE; i >= 0; --i)
      if(isPrint){
         printf("%d", a[i]);
      }
      else if(a[i]){
         printf("%d", a[i]);
         isPrint = 1;
      }
     printf("\n");
}
int main()
{
  int i, n;
  
  //freopen("t1.txt", "r", stdin);
 // freopen("ttt1.txt", "w", stdout);
 
  while(scanf("%d", &n) != EOF){
      memset(ans, 0, sizeof(ans));
      ans[0] = 1;
      for(i = 2; i <= n; ++i)
        Multiply(i);
      Print(ans);
  }
   
  system("pause");
  return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章