Created
December 19, 2009 09:57
-
-
Save bert/260030 to your computer and use it in GitHub Desktop.
Add number snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NUMBER add (NUMBER a, NUMBER b) | |
{ | |
int i; | |
int carry; | |
int aux; | |
int vec[MAX]; | |
NUMBER result; | |
if (a.length <= b.length) | |
aux = b.length; | |
else | |
aux = a.length; | |
carry = 0; | |
for (i = 0; i <= aux; i++) | |
{ | |
vec[i] = (a.vdigit[i] + b.vdigit[i] + carry) % a.base; | |
carry = (a.vdigit[i] + b.vdigit[i] + carry) / a.base; | |
} | |
if (carry > 0) | |
{ | |
vec[i] = carry; | |
aux = aux + 1; | |
} | |
result = createNumber (vec, a.base, aux); | |
return result; | |
} | |
/* EOF */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment