Factorial very good, recursive on the line, but for the larger number, factorial results very very large, wood has a way, can only be handled by string.
We use string multiplication to do it. After testing, this program can run a maximum of n value of almost 3000, and Windows on the scientific calculator of the same:)
String multiply (string num1, String num2) {int len1 = Num1.size (), len2 = Num2.size (), Len = Len1 + len2; String str (len, ' 0 '); for (int i = len1-1; I >= 0; i--) {int a = Num1[i]-' 0 '; for (int j = len2-1, k = Len2 + i; j >= 0; J--, k--) {int b = num2[j]-' 0 '; int c = str[k]-' 0 '; int t = b * a + C; STR[K] = t% 10 + ' 0 '; int d = (str[k-1]-' 0 ') + T/10; if (d >=) str[k-2] = str[k-2]-' 0 ' + D/10 + ' 0 '; STR[K-1] = d% 10 + ' 0 '; }} int x = 0; while (str[x] = = ' 0 ') x + +; if (Str.substr (x, len-x) = = "") return "0"; return Str.substr (x, len-x); }string itoa (int n) {string s= ""; do{s+=n%10+ ' 0 '; n/=10; }while (n); Reverse (S.begin (), S.end ()); return s;} string fun (int n) {string s="1"; for (int i=2;i<=n;i++) {s=multiply (S,itoa (i)); } return s;}
Finding the factorial algorithm of large numbers