大数相乘的源码
2012-10-23 20:17
134 查看
http://topic.csdn.net/u/20080203/10/64d519c1-030c-4725-abe4-e4d1061e894c.html
有空写注释。。。
其他网址:
/article/7352126.html
http://webdancer.is-programmer.com/posts/17711.html-----大数的加减乘除都实现了,值得一看。。。
/article/4620102.html---C++实现,看下面评论,文章中的代码好像有bug。
http://topic.csdn.net/t/20031217/21/2575135.html--大数类的初始化
有空写注释。。。
# include<stdio.h> # include<string.h> # include<malloc.h> void multiply(char* a,char* b,char* c) { int i,j,ca,cb,* s; ca=strlen(a); cb=strlen(b); s=(int*)malloc(sizeof(int)*(ca+cb)); for (i=0;i<ca+cb;i++) s[i]=0; for (i=0;i<ca;i++) for (j=0;j<cb;j++) s[i+j+1]+=(a[i]-'0')*(b[j]-'0'); for (i=ca+cb-1;i>=0;i--) if (s[i]>=10) { s[i-1]+=s[i]/10; s[i]%=10; } i=0; while (s[i]==0) i++; for (j=0;i<ca+cb;i++,j++) c[j]=s[i]+'0'; c[j]='\0'; free(s); }
其他网址:
/article/7352126.html
http://webdancer.is-programmer.com/posts/17711.html-----大数的加减乘除都实现了,值得一看。。。
/article/4620102.html---C++实现,看下面评论,文章中的代码好像有bug。
http://topic.csdn.net/t/20031217/21/2575135.html--大数类的初始化