High-precision operations are easy to implement in Java, just like A + b problem, because Java provides the appropriate class libraries and APIs, but there are no ready-made classes and APIs for you to call in C + +. In the spirit of "hands-on, clothed" coder, or on their own. Let's take a look at how to make the factorial of a large number using C + +.
/**from: "Algorithmic Competition Primer"-Rujia *author:yq_beyond *date:2015.03.29*//*High-precision operations in C + +*/#include<iostream>#include<cstring>#include<cstdio>using namespacestd;Const intMAXN = the;intRES[MAXN];intMain () {intI, J, N; while(1) {scanf ("%d",&N); memset (Res,0,sizeof(res)); res[0] =1; intCut =1; for(i =1; I <= N; i++) { intCNT =0; for(j =0; J < Cut; J + +) { ints = res[j] * i +CNT; RES[J]= s%Ten; CNT= S/Ten; } for(; CNT! =0; J + +) { ints = res[j] * i +CNT; RES[J]= s%Ten; CNT= S/Ten; Cut++; } } //For (j = maxn-1; J >= 0; j--) if (res[j]) break; for(i = cut-1; I >=0; i--) printf ("%d", Res[i]); printf ("\ n"); } return 0;}
Large number factorial (c + +)