求哪位高手看我这个程序哪里错了,真心不知道啊
#include<stdio.h>#include<string.h>
#define MAXNUM 200
typedef char datatype;
typedef struct
{
datatype data[MAXNUM];
int len;
}SString;
int compare(const datatype *a,const datatype *b)
{
int lena=strlen(a);
int lenb=strlen(b);
if(lena!=lenb)
return lena>lenb?1:-1;
else
return strcmp(a,b);
}
void Add(datatype *augend,datatype *addend,datatype *sum) //加法运算
{
int caug[MAXNUM]={0};
int cadd[MAXNUM]={0};
int csum[MAXNUM]={0};
int carry=0;
int s=0;
int lenaug=strlen(augend),lenadd=strlen(addend);
int lenmin=lenaug<lenadd?lenaug:lenadd;
int i,j;
for(i=0;i<lenaug;i++)
{
caug[i]=augend[lenaug-1-i]-'0';
}
for(i=0;i<lenadd;i++)
{
cadd[i]=addend[lenadd-1-i]-'0';
}
for(i=0;i<lenmin;i++)
{
s=caug[i]+cadd[i]+carry;
csum[i]=s%10;
carry=s/10;
}
while(i<lenaug)
{
s=caug[i]+carry;
csum[i]=s%10;
carry=s/10;
i++;
}
while(i<lenadd)
{
s=cadd[i]+carry;
csum[i]=s%10;
carry=s/10;
i++;
}
if(carry>0)
{
csum[++i]=carry;
}
for(j=0;j<i;j++)
{
sum[j]=csum[i-1-j];
}
sum[i]='\0';
}
void Sub(datatype *minuend,datatype *subtrahend,datatype *difference)
{
int len,lenm,lens,lenmin,i,j,k;
int flag;
int cm[MAXNUM]={0};
int cs[MAXNUM]={0};
int cd[MAXNUM]={0};
if(strcmp(minuend,subtrahend)==0)
{
strcpy(difference,"0");
}
lenm=strlen(minuend),lens=strlen(subtrahend);
lenmin=lenm<lens?lenm:lens;
if(compare(minuend,subtrahend)>0)
{
flag=0;
for(i=0;i<lenm;i++)
{
cm[i]=minuend[lenm-1-i]-'0';
}
for(i=0;i<lens;i++)
{
cs[i]=subtrahend[lens-1-i]-'0';
}
}
else
{
flag=0;
for(i=0;i<lenm;i++)
{
cs[i]=minuend[lenm-1-i]-'0';
}
for(i=0;i<lens;i++)
{
cm[i]=subtrahend[lens-1-i]-'0';
}
}
for(i=0;i<lenmin;i++)
{
if(cm[i]>=cs[i])
cd[i]=cm[i]-cs[i];
else
{
cd[i]=cm[i]+10-cs[i];
--cd[i++];
}
}
len=lenm>lens?lenm:lens;
if(i<len)
{
if(cm[i]>=0)
cd[i]=cm[i];
else
{
cd[i]=cm[i]+10;
--cd[i+1];
}
i++;
}
while(cd[i-1]==0)
i--;
j=0;
if(flag=1)
{
difference[j++]='-';
for(k=i-1;k>=0;k--,j++)
{
difference[j]=cd[k]='0';
}
difference[j]='\0';
}
}
void Mul(datatype *multiplicand,datatype *multiplier,datatype *product)
{
int cd[MAXNUM]={0};
int cr[MAXNUM]={0};
int cp[MAXNUM]={0};
datatype tcp[MAXNUM]="";
int lenD=strlen(multiplicand),lenR=strlen(multiplier);
int i,j,k;
int carry;
int mul;
for(i=0;i<lenD;i++)
{
cd[i]=multiplicand[lenD-1-i];
}
for(i=0;i<lenR;i++)
{
cr[i]=multiplier[lenR-1-i];
}
strcpy(product,"0");
for(i=0;i<lenR;i++)
{
carry=0;
for(j=0;j<lenD;j++)
{
mul=cd[j]*cr[j]+carry;
cp[j]=mul%10;
carry=mul/10;
}
if(carry>0)
{
cp[j++]=carry;
}
while((j-1)==0)
{
--j;
}
for(k=0;k<j;k++)
tcp[k]=cp[j-1-k];
for(j=0;j<i;j++)
tcp[k++]='0';
tcp[k]='\0';
Add(product,tcp,product);
}
}
void Div(datatype *dividend ,datatype *divisor,datatype *quotient,datatype *remainder)
{
datatype buf[2]="0";
int i,j,s,k;
if(compare(dividend,divisor)==0)
{
strcpy(quotient,"1");
strcpy(remainder,"0");
return;
}
if(strcmp(divisor,"0")==0||compare(dividend,divisor)<0)
{
strcpy(quotient,"0");
strcpy(remainder,dividend);
return;
}
strcpy(remainder,"");
for(i=0,k=0;dividend[i]!='0';i++)
{
s=0;
buf[0]=dividend[i];
strcat(remainder,buf);
while(compare(remainder,divisor)>=0)
{
s++;
Sub(remainder,divisor,remainder);
}
quotient[k++]=s+'0';
if(strcmp(remainder,"0")==0)
strcpy(remainder,"");
}
quotient[k]='\0';
for(i=0;quotient[i]=='0';i++)
for(j=i;j<=k;j++)
quotient[j-1]=quotient[j];
}
int Rad(datatype *tostr,datatype *fromstr)
{
int i=0,j=0,len;
while (fromstr[i]!='.'&&fromstr[i]!='\0')
tostr[j++]=fromstr[i++];
len=i++;
while(fromstr[i]!='\0')
tostr[j++]=fromstr[i++];
return i-len-1;
}
int main(int argc,char *argv[])
{
datatype a[MAXNUM]={0};
datatype b[MAXNUM]={0};
datatype c[3*MAXNUM]={0};
datatype d[MAXNUM]={0};
printf("请输入第一个数:");
gets(a);
printf("请输入第二个数:");
gets(b);
Add(a,b,c);
printf("两者之和为:");
puts(c);
Sub(a,b,c);
printf("两者之差为:");
puts(c);
Mul(a,b,c);
printf("两者之积为:");
puts(c);
Div(a,b,c,d);
printf("两者之商为:");
puts(c);
printf("余数为:");
puts(d);
return 0;
}