(大整数乘法(str_a * str_b = str_c)
#include<stdio.h>
#include<string.h>
#define N 1009
void Strrev(char str[])
{
int i,j=0;
char s[1009];
for(i=strlen(str)-1;i>=0;i–)
s[j++]=str[i];
s[j]=’\0′;
strcpy(str,s);
}
void mul(char str_a[N], char str_b[N], char str_c[N])
{
char a[N],b[N];
int c[2*N];
char C[2*N];
int i,j,len_a,len_b;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
memset(C,0,sizeof(C));
strcpy(a,str_a);strcpy(b,str_b);
Strrev(a);Strrev(b);
len_a=strlen(a);len_b=strlen(b);
for(i=0;i<len_a;i++)
a[i]=a[i]-‘0’;
for(i=0;i<len_b;i++)
b[i]=b[i]-‘0’;
for(i=0;i<len_b;i++)
for(j=0;j<len_a;j++)
c[i+j]+=b[i]*a[j];
for(i=0;i<len_a+len_b;i++)
{
c[i+1]=c[i+1]+c[i]/10;
c[i]=c[i];
}
for(i=0;i<len_a+len_b;i++)
C[i]=c[i]+’0′;
while(C[i]==0||C[i]==’0′)i–;
C[i+1]=0;
Strrev(C);
strcpy(str_c,C);
}
int main()
{
char str_a[N],str_b[N],str_c[N];
gets(str_a);
gets(str_b);
mul(str_a,str_b,str_c);
puts(str_c);
return 0;
}