Usually solves the problem of large numbers of operation data out of range, overflow. Arrays are generally used to simulate. The n! can be thought of as the process of multiplying two integers at a time, so the process of multiplying by large numbers can be simulated. Just need to add some variables to store the values of the middle carry and the current bit.
#include <iostream>using namespace std; #define Max_wei 100000int result[max_wei];int wei_location;int up;int Main () {int i,n; Int J; while (scanf ("%d", &n)!=eof) {memset (result,0,sizeof (result)); RESULT[1] = 1; Wei_location=1; The number of bits of the current result, which facilitates multiplication and final output up = 0; if (n==0 | | n==1) {printf ("1\n"); Continue } for (i=2;i<=n;i++)//n! Each number in the {for (J =1,up =0;j<=wei_location;j++)//simulation multiplication step: Each is multiplied by the current number {Result[j] = Result[j] *i + up; Current number + front carry number up = RESULT[J]/10; RESULT[J] =result[j]%10; Save one per digit} while (up > 0) {result[j++] + = up%10; Pay attention to jump out is J is Taichi up= UP/10; } wei_location= j-1;//Notice that the J is Taichi} for (i = wei_location;i>=1;i--) (i!=1)? printf ("%d", Result[i]): printf ("%d\n", Result[i]); } return 0;}
Large number n!