#include<stdio.h>
#include<string.h>
#define MAX 100
/* the size of multiplicator */
#define ANS_MAX200
/* the size of answer */
intchange_char2int(char);
/* changecharacter type to integer type */
voidhigh_multiply(char * a,char * b,char * ans);
/* precisionnumber multiply precision number */
void main(void)
{
char a[MAX],b[MAX];
/* a:1st number
b:2ndnumber */
char ans[ANS_MAX];
/* the answer array,character type */
printf("Input the 1st number:\n");
gets(a);
printf("Input the 2nd number:\n");
gets(b);
high_multiply(a,b,ans);
/*print answer*/
printf("\n%s * %s = %s\n",a,b,ans);
}
intchange_char2int(char c)
{
if ((c>='0')&&(c<='9'))
return (c-'0');
else
{
printf ("Error!\n");
return -1;
}
}
void high_multiply(char * a,char * b,char * ans)
{
intans_tmp[ANS_MAX]; /* the temporarily answer array */
int i,j,key=0;
inta_len=strlen(a),b_len=strlen(b);
intt,ans_len=ANS_MAX-1;
for(i=0;i<ANS_MAX;i++)
ans_tmp=0;
/* initialize the answer array */
for(i=b_len-1;i>-1;i--)
{
inttemp_b=change_char2int(b);
t=ans_len--;
for(j=a_len-1;j>-1;j--)
{
inttemp_a=change_char2int(a[j]);
ans_tmp[t]+=temp_a*temp_b;
ans_tmp[t-1]+=ans_tmp[t]/10;
ans_tmp[t]%=10;
t--;
}
}
/* change theanswer array to character type */
for(i=0,j=0;i<ANS_MAX;i++)
{
if(ans_tmp==0&&key==0) continue;
key=1;
ans[j++]=ans_tmp+'0';
}
if (key==0)ans[j++]='0';
ans[j]='\0';
}
注:(代码在 Turbo C 2.0 环境下编译通过)
这只是个例子,和你问题的有点不一样
[
本帖最后由 清风拂晓 于 2011-2-21 09:44 编辑 ]