1. ## Dynamic array question

How to write functions to add 2 big integers with dynamic arrays?
The 2 integers are input by users.
2 integer arrays store the input such that :
x[0]=number of digits
x[1]=1 st digit of the integer input (starting from the right)
x[2]=2 nd digit of the integer input
... & so on
eg.
input integer 1: 456
x[0]=3
x[1]=6
...

There is function to store the input:
void input(int*);
Another takes the 2 integer arrays as parameter to add the integers.

How to divide the input integers into digits?
If I know how to write void input(int*), then I may know how to write int *add(int *,int*)
Anyone can help? Any similar example on the net that can inspire me?

2. Could you please be more specific?

3. If you type in
13579

I can see that you might store 5 in x[0] representing the length, but what would you store in x[1]?
Would it be '1', the first digit of input?
Would it be '9', the least significant value of the input?

> how to divide the input integer into digits
It's a lot easier if you read it as a string, expecially if you're considering very long input.

The rest is just modelling how you would add two numbers on paper
- start at the right, and add with carry your way to the left.

4. Originally Posted by Salem
If you type in
13579

I can see that you might store 5 in x[0] representing the length, but what would you store in x[1]?
Would it be '1', the first digit of input?
Would it be '9', the least significant value of the input?

> how to divide the input integer into digits
It's a lot easier if you read it as a string, expecially if you're considering very long input.

The rest is just modelling how you would add two numbers on paper
- start at the right, and add with carry your way to the left.
Oops,I forgot to mention that, sorry.
It should be reverse so x[1] should be 9 according to your example.
If string can't be used, how to divide the integer into digits?
I asked this question as it is given that the function to store the input:
void input(int*);
takes an integer as parameter.

5. Well you extract digits from an integer using /10 and %10 operations in some kind of loop.

6. Thanks, I always forget this.

7. The magic phrase you're looking for is "arbitrary precision arithmetic". It's implemented by the GNU MP library - see

http://www.swox.com/gmp/

and if you just want to use it rather than compile code for it, there are a number of implementations including Maxima, an open-source descendent of MACSYMA:

http://maxima.sourceforge.net/

8. Thanks, these are quite useful for me.