Reducing steps for long addition program This is a program that I wrote to add two numbers together that are too large for the C language to store.  It stores the numbers as strings instead and processes one digit at a time. But I suspect that the program could be done in fewer steps.  In what ways can I reduce the size of my program?  Where am I taking more steps than necessary?

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

int main()
{
    char *a = "1490438498359508";
    char *b = "1575390843059845";
    char *sum = "";
    char str[15] = "";
    char src[512];
    int carry = 0;
    int alength = strlen(a);
    int blength = strlen(b);
    int n;
    int i;
    int c, d;

    for (n=1; n&lt;blength+1; n++) {
        int c=0, d=0;
        i = 0;
        c = a[alength-n]-48;
        d = b[blength-n]-48;
        i = c+d;
        if (carry == 1) {
            i=i+1;
        }
        if (i &gt; 9) {
            i = i-10;
            carry=1;
        } else {
            carry=0;
        }
        int aInt = i;
        char str[15] = "";
        sprintf(str, "%d", aInt);
        strcat(src, str);

    }
    int nlength = strlen(src);
    int x;
    for (x=0; x&lt;nlength+1; x++) {
        printf("%c", src[nlength-x]);
    }
    printf("\n");
    return 0;
}
1) It seems that you assumed length of a and b are the same. But if a has a bigger length than b you don't process all digits! Your loop should go over maximum of lengths of a and b and whenever one operand has no digit any more, use 0.

2) You can write these lines

i = c+d;
if (carry == 1) {
    i=i+1;
}


like this:

i = c + d + carry


use arithmetic operations when branches are not necessary.

3) The result of addition has always at most one digit more than the bigger operand. So you can allocate a string once and avoid concatenation in each iteration (just put the result digit in its right place).

4) You can reduce number of iterations by using the fact that you can add in higher bases! This way instead of a string, use an integer array and treat the
operands, say in base 10000. Now each digit in this base is a 4 digit number in base 10. Everything will be the same, except for setting the value of carry.
With base 10^4, you reduced number of iteration to one-forth. You can go further till where integer range supports safely (10^8).