#include <bits/stdc++.h>
using namespace std;
int a[200];
int b[200];
int c[200];
string sa,sb;
int main(){
cin>>sa>>sb;
int len = max(sa.length(), sb.length());
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
int index=0;
for(int i=sa.length()-1;i>=0;i--){
a[index++] = sa[i]-'0';
}
index = 0;
for(int i=sb.length()-1;i>=0;i--){
b[index++] = sb[i]-'0';
}
int cy = 0;
int i;
for(i=0;i<len;i++){
c[i] = a[i] + b[i] + cy;
cy = c[i]/10;
c[i] %= 10;
}
if(cy != 0){
c[i] = cy;
len++;
}
for(int i=len-1;i>=0;i--){
printf("%d",c[i]);
}
}
【高精度】加法模板
最新推荐文章于 2021-12-04 16:56:41 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)