大整数的一些算法(Some algorithms for large integers).docVIP

  • 1
  • 0
  • 约5.24千字
  • 约 15页
  • 2017-10-06 发布于河南
  • 举报

大整数的一些算法(Some algorithms for large integers).doc

大整数的一些算法(Some algorithms for large integers)

大整数的一些算法(Some algorithms for large integers) Some large integer algorithm / write, online can be found, but not complete * program, and then write a relatively complete procedure, issued on the Blog * / #include stdio.h #define MAXINT 1000 Int compare (int, a[], int, b[]); Int bigplus (int, a[], int, b[], int, c[]); Int bigsub (int, a[], int, b[], int, c[]); Int bigmult (int, a[], unsigned, int, B, int, c[]); Int bigmult2 (int, a[], int, b[], int, c[]); Int, bigdiv (int, a[], unsigned, int, B, int, c[], int, *d); Int, bigdiv2 (int, a[], int, b[], int, c[], int, d[]); Int main (int, argc, char, *argv[]) { Int a[MAXINT]={10,5,4,6,5,4,3,2,1,1,1}; / / or multiplicand divisor Int b[MAXINT]={7,7,6,5,4,3,2,1}; / / multiplier or divisor Int c[MAXINT], d[MAXINT]; //c[] store provider; d[] stores remainder Int div=1234; / / small multiplier or small divisor Int k=0; Int *res=k; / / pointer small integer remainder Bigplus (a, B, C); Bigsub (a, B, C); Bigmult (a, div, C); Bigmult2 (a, B, C); Bigdiv (a, div, C, res); Bigdiv2 (a, B, C, D); Getchar (); Return 0; } Int compare (int a[], int b[]) / / relatively large integers { Int i; If (a[0]b[0]) return 1; / / compare a, B number determines the return value Else if (a[0]b[0]) return -1; Comparison of else / / equal number of { I=a[0]; While (a[i]==b[i]) / bit comparison I--; If (i==0) return 0; Else if (a[i]b[i]) return 1; Else return -1; } } Int bigplus (int a[], int b[], int c[]) / / large integer addition { Int, I, len; Len= (a[0]b[0]: a[0]: b[0]); //a[0] b[0] holds the array length, and Len is the longer one For (i=0; iMAXINT; i++) / / array 0 C[i]=0; For (i=1; i=len; / / i++) was calculated for each bit value { C[i]+= (a[i]+b[i]); If (c[i]=10) { C[i]-=10; / / take a bit more than 10 C[i+1]++; / / 1 high } } If (c[i+1]0) len++; C[0]=len; //c[0] save the actual length of the result array Printf (Big integers add:; For (i=len; i=1; i--) Printf (%d, c[i]); / / print results Printf (\n; Return 0; } Int bigsub (int a[], int b[], in

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档