u012980441 于 2014.01.06 21:31 提问

C语言问题，A+Bproblems，求帮助

1.1 2.9
1.1111111111 2.3444323343
1 1.1

4
3.4555434454
2.1

#include
#include
int main()
{
int i,j,k,l,len1,len2,flag,sum[1100],p,zb;
char a[400],b[400];
while(scanf("%s%s",a,b)!=EOF)
{
len1=strlen(a);len2=strlen(b);
memset(sum,0,sizeof(sum));/////
flag=0;
for(i=0;a[i];i++)
if(a[i]=='.')
break;
k=i+1; //////0~~~i-1wei zhengshu
if(a[i])
flag=1; ///1 zhengshu 0 xiaoshu
for(j=0;b[j];j++)
if(b[j]=='.')
break;
l=j+1; /////0~~~~j-1 wei zhengshu
if(b[j])
flag=1;
if(i>j)
zb=i+1; ///zui da you zb wei zhengshu
else
zb=j+1;

``````    p=zb;      //// p wei zheng shu
i--;
j--;
for(;;i--,j--)
{
if(i>=0&&j>=0)
sum[p--]=a[i]-'0'+b[j]-'0';       ////sum[0] liu gei jinwei
else if(i>=0&&j<0)
sum[p--]=a[i]-'0';
else if(i<0&&j>=0)
sum[p--]=b[j]-'0';
else if(i<0&&j<0)
break;
}
p=zb+1;        //// p liu gei xiaoshudian
for(;;k++,l++)
{
if(k<len1&&l<len2)
sum[p++]=a[k]-'0'+b[l]-'0';    ///xiaoshu bufen jisuan
else if(k<len1&&l>=len2)
sum[p++]=a[k]-'0';
else if(k>=len1&&l<len2)
sum[p++]=b[l]-'0';
else if(k>=len1&&l>=len2)
break;
}
for(i=p-1;i>=0;i--)
if(sum[i]>=10)
{
sum[i]=sum[i]-10;
sum[i-1]++;
}
i=0;
while(sum[i]==0)
i++;
for(;i<=zb;i++)
printf("%d",sum[i]);
p--;
while(sum[p]==0&&p>=0)
p--;
if(p<=zb)
flag=0;
if(flag)
{
printf(".");
for(i=zb+1;i<=p;i++)
printf("%d",sum[i]);
}
printf("\n");
}
return 0;
``````

}