您的位置:首页 > 其它

(转)两个大数相乘

2012-10-03 11:03 274 查看
#include

#include

#include

using namespace std;

void Multiply(const char *a,const char *b,int n,int m,char res[200],int *k)

{

int i,j,s;

int pos=0;

int p[100]={0};

int q[100]={0};

int t;

int max=0;

int min=0;

int temp[200]={0};

for(i=0;i

{

p[i]=a[n-i-1]-'0';

}

for(i=0;i

{

q[i]=b[m-i-1]-'0';

}

max=((n>m)?n:m);

min=((n

for(i=0;i

{

pos=i;

for(j=0;j

{

if(n>m)

{

temp[pos]+=q[i]*p[j];

}

else

{

temp[pos]+=p[i]*q[j];

}

if(temp[pos]>10)

{

t=temp[pos]/10;

temp[pos]=temp[pos];

temp[pos+1]+=t;

}

pos++;

}

}

if(temp[pos]!=0)

{

pos++;

}

for(s=0;s

{

res[s]=temp[pos-s-1]+'0';

}

res[pos]='\0';

*k=pos;

cout<<"res="<<res<<endl;

cout<<"k="<<*k<<endl;

}

int main()

{

char *a="8615261895132";

char *b="15261895132";

char res[200];

int *k=new int[1];

if(NULL==k)

{

exit(1);

}

memset(res,0,sizeof(res));

Multiply(a,b,strlen(a),strlen(b),res,k);

delete [] k;

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  delete null