自己写的大整数乘法C++程序,请指正。
#include <iostream>
using namespace std;
int multi(const int a[], const int b[], int c[], const int len)
{
for (int k=0; k<2*len-1; k++)
{
for (int i=0; (i<k+1)&&(i<len); i++)
{
if (k-i<len)
{
int temp=a[i]*b[k-i];
c[k]+=temp;
}
}
cout<<"c["<<k<<"] = "<<c[k]<<endl;
}
return 0;
}
int out(int c[], const int len)
{
for (int i=2*len-2; i>0; i--)
{
if (c[i]>9)
{
c[i-1]+=c[i]/10;
c[i]=c[i]%10;
}
}
return 0;
}
int main()
{
const int a[]={1, 2, 3, 4, 5, 5, 1, 2, 3, 4};
const int b[]={6, 7, 8, 9, 0, 5, 1, 2, 3, 4};
static const int len = 9;
int c[2*len+2]={0};
multi(a, b, c, len+1);
out(c, len+1);
for(int i=0; i<2*len+1; i++)
cout<<c[i];
cout<<endl;
return 0;
}