[OCLUG-devel] calculations one digit at a time

Michael Elkins michael.elkins at gmail.com
Sun Jul 11 22:23:26 PDT 2004


On Sun, 11 Jul 2004 11:18:46 -0700, Michael Elkins
<michael.elkins at gmail.com> wrote:

>     for (i=0; i<10; i++) {
>         c[i] = a[i] + b[i];
>         if (c[i] >= 10) {
>             c[i+1]++;
>             c[i] -= 10;
>         }
>     }

Just for sake of completeness, the above code has an error in it.  The
second line should
read:
    c[i] += a[i] + b[i];
Otherwise any carries that are done would be overwritten.

-Michael


More information about the OCLUG-devel mailing list