高精度之阶乘的和
作者:互联网
输入:50
输出:31035053229546199656252032972759319953190362094566672920420940313
#include<stdio.h> #include<stdlib.h> #define length 100000 int b[length]; void add(int a[],int b[]) { int i; int j; for(i=0;i<length-1;i++) { //printf("%d ",a[i]); j = a[i]+b[i]; if(j>=10) { b[i] = j%10; b[i+1]+=j/10; } else b[i]= j ; } } int main() { int a[length]; int i; for(i=0;i<length;i++) b[i] = 0; int n; scanf("%d",&n); int k; for(k=1;k<=n;k++) { for(i=0;i<length;i++) { a[i] = 0; } a[0] = 1; //printf("test"); for(i=1;i<=k;i++) { int jinwei = 0; int j = 0; int temp; while(j<length) { temp = jinwei; jinwei = (a[j]*i+jinwei)/10; a[j] = (a[j]*i + temp)%10; j++; } } add(a,b); } int count; count = length-1; while(!b[count]) { count--; } while(count>=0) { printf("%d",b[count]); count--; } return 0; }
参考链接:高精度计算_flymist的博客-CSDN博客_高精度计算
阶乘(高精度)_我如一阵风飘过的博客-CSDN博客_高精度阶乘
标签:10,高精度,int,博客,length,阶乘 来源: https://www.cnblogs.com/kmxojer/p/16469628.html