#include #define SIZE 5 main() { char number1[SIZE]; /* stores the first number */ char number2[SIZE]; /* stores the second number */ char number3[SIZE]; /* stores the addition */ char symbol; /* stores the current symbol read */ int i; int carry; /* records the carry value during addition */ /* read the first number */ printf("Enter a %d digit number: ", SIZE); for (i = 0; i < SIZE; i++) { number1[i] = getchar() - 48; } /* read the second number */ printf("Enter another %d digit number: ", SIZE); for (i = 0; i < SIZE; ) { symbol = getchar(); if ((symbol >= '0') && (symbol <= '9')) { /* ignore non-digits */ number2[i] = symbol - 48; i++; } } /* add two numbers */ carry = 0; /* initial carry is 0 */ for (i = SIZE-1; i >= 0; i--) { number3[i] = number1[i] + number2[i] + carry; if (number3[i] >= 10) { /* carry is 1 */ number3[i] = number3[i] - 10; carry = 1; } else /* carry is 0 */ carry = 0; } if (carry == 1) { /* shift digits of number3 */ for (i = SIZE; i > 0; i--) number3[i] = number3[i-1]; number3[0] = 1; } /* output the result */ printf("The sum is: "); if (carry == 1) { /* number3 has SIZE+1 digits */ for (i = 0; i <= SIZE; i++) printf("%c", number3[i]+48); } else { /* number3 has SIZE digits */ for (i = 0; i < SIZE; i++) printf("%c", number3[i]+48); } printf("\n"); }