数组实现大数相乘
来源:互联网 发布:linux硬件级虚拟机 编辑:程序博客网 时间:2024/05/02 00:12
还很粗糙,效率也不太高,有时间再封装到c++类。
//数组自乘测试
void multiply(int a[],int len,int n,int dd)
{
int LEN=len;
int N=n;
//初始化result
int yy=LEN-1,xx=MAX-1;
while(yy>=0)
{
aa[xx--]=a[yy--];
}
for(int i=1;i<N;i++)
{
for(int i=0;i<MAX;i++)
result[i]=0;
int oo=0;
for(int k=LEN-1;k>=0;k--)
{
//clear temp
for(int ss=0;ss<MAX;ss++)
temp[ss]=0;
int carry=0;
int bit=0;
for(int j=MAX-1;j>=0;j--)
{
while(aa[j]*a[k]+carry>=10)
{
int temptemp=aa[j]*a[k]+carry;
temp[MAX-1-bit-oo]=(aa[j]*a[k]+carry)%10;
bit++;
j--;
carry=temptemp/10;
}
temp[MAX-1-bit-oo]=aa[j]*a[k]+carry;
carry=0;
bit++;
}
for(int dd=MAX-1;dd>=0;dd--)
{
int resultcarry=0;
while(temp[dd]+result[dd]+resultcarry>=10)
{
result[dd]=(temp[dd]+result[dd]+resultcarry)%10;
resultcarry=1;
dd--;
}
result[dd]=temp[dd]+result[dd]+resultcarry;
resultcarry=0;
}
oo++;
}
int xx=MAX-1;
while(xx>=0)
{
aa[xx]=result[xx];
xx--;
}
}
print(dd);
}
//数组自乘测试
void multiply(int a[],int len,int n,int dd)
{
int LEN=len;
int N=n;
//初始化result
int yy=LEN-1,xx=MAX-1;
while(yy>=0)
{
aa[xx--]=a[yy--];
}
for(int i=1;i<N;i++)
{
for(int i=0;i<MAX;i++)
result[i]=0;
int oo=0;
for(int k=LEN-1;k>=0;k--)
{
//clear temp
for(int ss=0;ss<MAX;ss++)
temp[ss]=0;
int carry=0;
int bit=0;
for(int j=MAX-1;j>=0;j--)
{
while(aa[j]*a[k]+carry>=10)
{
int temptemp=aa[j]*a[k]+carry;
temp[MAX-1-bit-oo]=(aa[j]*a[k]+carry)%10;
bit++;
j--;
carry=temptemp/10;
}
temp[MAX-1-bit-oo]=aa[j]*a[k]+carry;
carry=0;
bit++;
}
for(int dd=MAX-1;dd>=0;dd--)
{
int resultcarry=0;
while(temp[dd]+result[dd]+resultcarry>=10)
{
result[dd]=(temp[dd]+result[dd]+resultcarry)%10;
resultcarry=1;
dd--;
}
result[dd]=temp[dd]+result[dd]+resultcarry;
resultcarry=0;
}
oo++;
}
int xx=MAX-1;
while(xx>=0)
{
aa[xx]=result[xx];
xx--;
}
}
print(dd);
}
- 数组实现大数相乘
- 大数相乘,数组
- 实现两个大数相乘
- python实现大数相乘
- 大数相乘 C++实现
- C++ 实现大数相乘
- 大数相乘算法实现
- 大数相乘的实现
- Java实现大数相乘
- C++实现大数相乘
- 大数相乘 C++实现
- asp利用数组实现阶乘计算(大数相乘)
- 大数相乘的C++实现
- 大数相乘-C语言实现
- 大数相乘代码-字符串实现
- 两个大数相乘-python实现
- 大数相加 相乘 java实现
- c语言实现大数相乘
- Unmi 学习 Groovy 之命名参数
- 深刻理解Linux进程间通信(IPC)
- Prototype使用学习手册指南之form.js
- 我的相册程序
- 关于prototype.js的一些技术说明 bind bindAsEventLinstener
- 数组实现大数相乘
- 黑屏后面藏了什么?--解读微软打击盗版
- 戴尔手握100亿美元现金扬言将展开收购
- 大中型网站架构探秘
- 关于Javascript定义函数和this使用的两点注意的地方
- Javascript对url进行编码的几个函数
- 2008.10.23 C基础
- 学习很累
- Prototype使用学习手册指南之Selector.js