c++高精度加法代码问题如下,解决提高二十悬赏
#include<iostream>#include<stdlib.h>#include<bits/stdc++.h>usingnamespacestd;intmain(...
#include <iostream>
#include<stdlib.h>
#include <bits/stdc++.h>
using namespace std ;
int main()
{
int x,y,jw,i,cd;
char a[255],b[255];
int aa[255],bb[255],cc[255];
cin>>a>>b;
for (i=0;i<=255;i++)
{aa[i]=0;bb[i]=0;cc[i]=0;
}
x=strlen(a);
y=strlen(b);
for (i=0;i<=x-1;i++)
{ aa[x-i]=a[i]-48; }
for (i=0;i<=y-1;i++)
{ bb[x-i]=b[i]-48; }
jw=0; cd=1;
while (cd<=x||cd<=y)
{
cc[cd]=aa[cd]+bb[cd]+jw;
jw=cc[cd]/10;
cc[cd]=cc[cd]%10;
cd++;
}
cc[cd]=jw;
if (cc[cd]==0)
{ cd--;
}
for (i=cd;i>=1;i--)
{cout<<cc[i];
}
return 0;
} 展开
#include<stdlib.h>
#include <bits/stdc++.h>
using namespace std ;
int main()
{
int x,y,jw,i,cd;
char a[255],b[255];
int aa[255],bb[255],cc[255];
cin>>a>>b;
for (i=0;i<=255;i++)
{aa[i]=0;bb[i]=0;cc[i]=0;
}
x=strlen(a);
y=strlen(b);
for (i=0;i<=x-1;i++)
{ aa[x-i]=a[i]-48; }
for (i=0;i<=y-1;i++)
{ bb[x-i]=b[i]-48; }
jw=0; cd=1;
while (cd<=x||cd<=y)
{
cc[cd]=aa[cd]+bb[cd]+jw;
jw=cc[cd]/10;
cc[cd]=cc[cd]%10;
cd++;
}
cc[cd]=jw;
if (cc[cd]==0)
{ cd--;
}
for (i=cd;i>=1;i--)
{cout<<cc[i];
}
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询