If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

can someone help me?

I do not know what to do with this help me please.

1. Consider the problem of adding two large positive integers, each at most twnty(20) digits long. One solution is to store the integers in an array where a single digit is placed in a single component of the array. for example the number 1,418,436,029 can be stored as shown below:

design an algorithm called addLong(int1,int2, sum) that will take two positive integers stored in two separtate arrays, in Array1 and Array2 in the manner described earlier, take their sum and store the result in a third called sumArray.

Re: can someone help me?

It doesnt need a code so it only needs an outline form if its coding i think i know what to do but since it says it should be in outline format i don't know but guess the arrays
is this correct?
Array1( int1)
/ 1 / 2 / 3 / 4 / 5 / 6 / 7 /
0 1 2 3 4 5 6

Re: can someone help me?

I would have figured that the required sum would be

/ 2 / 4 / 6 / 9 / 1 / 3 / 4 /
0 1 2 3 4 5 6

as when the value of an element exceeds 9, then the element value is a(i) % 10 and the value of the element to the left (ie a(i - 1)) is incremented by a(i) / 10 (integer arithmetic). This progates throughout the array from right to left.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Re: can someone help me?

Looking at it in the right direction.
Couple of things to look out for.

1. The 2 arrays are of 20 in length each. Each array can store 20 digits.
2. 3rd array 21 in length. Sum can add up and come up with one extra digit.
3. You have to store the number in either of these two formats (cant think of another way, if it exists),
a. Store Last digit first in array starting from last array index (Straightforward)
b. Store Last digit first in array starting from first array index.

For instance if you have 2 numbers,
1234
89
and have 2 arrays of length 5 each, and storing in this way
[1] [2] [3] [4] []
[8] [9] [] [] []
will yield a junk result.

Instead if you store the last digit first in array starting from last array index
[] [1] [2] [3] [4]
[] [0] [0] [8] [9]
Now your sum will be right.
Just add each array values from last index. Do a mod (%10) on result to get the carry forward and reminder. Carry forward gets added to next addition and reminder goes into the result array.

You could also store last digit first starting from first array index
[4] [3] [2] [1] []
[9] [8] [] [] []
Note that the digits have reversed their order.