看着看着,我想到了能否把输进来的数当成字符串,然后再转化成各个位数,再计算,我下来想一下,这个题目满有趣的!
幽幽黄桷兰----建四狼
#include<stdio.h>
#include<stdlib.h>
int *multi1=NULL,*multi2=NULL,*result=NULL;
int c=0,length1,length2;
int i,j,k,m,n,p,q,suffix;
main()
{
printf("Please input the length of multiplicand:");
scanf("%d",&length1);/*????????*/
multi1=(int *)malloc(length1*sizeof(int));
printf("Now enter the multiplicand:");
for(i=0;i<length1;i++)
scanf("%1d",multi1+i);
printf("Then please input the length of multiplier:");
scanf("%d",&length2);/*???????*/
multi2=(int *)malloc(length2*sizeof(int));
printf("Now enter the multiplier:");
for(j=0;j<length2;j++)
scanf("%1d",multi2+j);
result=(int*)malloc((length1+length2)*sizeof(int));
for(k=0;k<length1+length2;k++)
result[k]=0;
for(m=i-1;m>=0;m--)
for(n=j-1;n>=0;n--)
{
c=(*(multi1+m))*(*(multi2+n));
suffix=k-(i-m)-(j-n)+1;
*(result+suffix)+=c%10;
if(*(result+suffix)>=10)
{
*(result+suffix)=*(result+suffix)%10;
++*(result+suffix-1);
}
*(result+suffix-1)+=c/10;
if(*(result+suffix-1)>=10)
{
*(result+suffix-1)=*(result+suffix-1)%10;
++*(result+suffix-2);
}
}
for(p=0;!result[p];p++);
for(q=p;q<k;q++)
printf("%d",result[q]);
printf("\n");
free(multi1);
free(multi2);
free(result);
}