解题思路:
注意事项:
参考代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int ans,s;
char c[1000],d[1000];
while(scanf("%s%s",c,d)!=EOF)
{
int a[1001]={0},b[1001]={0};
int i=0,m=0;
for(int j=strlen(c)-1;i<strlen(c);i++,j--)
{
a[i]=c[j]-'0';
}
for(int n=strlen(d)-1;m<strlen(d);m++,n--)
{
b[m]=d[n]-'0';
}
//**转换
int l=(strlen(c)>strlen(d))?strlen(c):strlen(d);
for(s=0;s<l;s++)
{
ans=a[s]+b[s];
if(ans>=10)
{
a[s]=ans%10;//留数
a[s+1]+=ans/10; //进位
}
else
{
a[s]=ans;
}
}
if(a[s]>0)
cout<<a[s];
for(int q=s-1;q>=0;q--)
{
cout<<a[q];
}
cout<<endl;
s=0;
ans=0;
}
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:562 |
Tom数 (C语言代码)浏览:736 |
C语言训练-计算1977!* (C语言代码)浏览:899 |
简单的a+b (C语言代码)浏览:629 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:554 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:668 |
数组输出 (C语言代码)错误???浏览:566 |
简单的a+b (C语言代码)浏览:599 |
简单的for循环浏览:1410 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:616 |