Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- const int N = 12; // essential of number
- int main() {
- char a[N], b[N];
- int result[N];
- //------------------- initial value -------------------
- for (int i = 0; i < N; ++i) {
- a[i] = b[i] = '0';
- result[i] = -1;
- }
- //------------------------ input -----------------------
- scanf("%s %s", a, b);
- // --------- find length of string 'a' and 'b' ---------
- int len_a = strlen(a);
- int len_b = strlen(b);
- int i;
- //-------------- swap string 'a' and 'b' ---------------
- for (i = 0; i < len_a/2; ++i) {
- char c = a[i];
- a[i] = a[len_a - i - 1];
- a[len_a - i - 1] = c;
- }
- for (i = 0; i < len_b/2; ++i) {
- char c = b[i];
- b[i] = b[len_b - i - 1];
- b[len_b - i - 1] = c;
- }
- //------------ calculate plussing - processing ----------
- i = 0;
- while (i < len_a && i < len_b) {
- result[i] = a[i] - '0' + b[i] - '0';
- ++i;
- }
- while (i < len_a) {
- result[i] = a[i] - '0';
- ++i;
- }
- while (i < len_b) {
- result[i] = b[i] - '0';
- ++i;
- }
- int tod = i = 0;
- int ans[N];
- int ans_i = 0;
- while (result[i] != -1) { // using array to be stack
- ans[ans_i++] = (result[i]+tod) % 10;
- tod = (result[i]+tod) / 10;
- ++i;
- }
- if(tod > 0)ans[ans_i++] = tod;
- //--------------------- output --------------------------
- while (--ans_i >= 0) {
- printf("%d", ans[ans_i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement