Figure 1: Pseudocode to add two BigNums
BigNum add(BigNum a, BigNum b){ //if |a| > |b| reverse terms if(|a|>|b|) return(add(b,a)); BigNum sum; // |a| <= |b| carry = 0 for(i = 0;i<= digits of a; i++){ temp = a[i] + b[i] + carry //carry is always 1 or 0 carry = temp/10 sum[i] = temp % 10 } for(i=(digits of a) + 1; i<=digits of b; i++){ //copy the rest of b, and //keep track of past carries temp = b[i] + carry carry = temp/10 sum[i] = temp % 10 } if (carry) sum(i) = carry; return sum; }