解题思路:
注意事项:
参考代码:
#include<bits/stdc++.h> using namespace std; int main() { char a[100]; char b[100]; int c[200]; int cont = 0, i = 0; cin >> a; cin >> b; int p = strlen(a) - 1, q = strlen(b) - 1; while (p != -1 || q != -1) { if (p == -1) { int tem = (b[q] - '0') + cont; cont = tem / 10; c[i++] = tem % 10; q--; } else if (q == -1) { int tem = (a[p] - '0') + cont; cont = tem / 10; c[i++] = tem % 10; p--; } else { int tem = (a[p] - '0') + (b[q] - '0') + cont; cont = tem / 10; c[i++] = tem % 10; p--; q--; } } if (cont != 0)c[i++] = cont; for (int j = i - 1; j > -1; j--) { cout << c[j]; } }
0.0分
2 人评分
数列排序 (C语言代码)浏览:858 |
【明明的随机数】 (C++代码)浏览:834 |
用筛法求之N内的素数。 (C语言代码)浏览:1385 |
兰顿蚂蚁 (C++代码)浏览:1159 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:490 |
简单的a+b (C语言代码)浏览:444 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:871 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:1059 |
C语言程序设计教程(第三版)课后习题7.5 (C++代码)浏览:1460 |
简单的a+b (C语言代码)浏览:676 |