
September 7th, 2013, 10:52 PM
#1
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:
/ / / / / 1 / 4 / 1 / 8 / 4 / 3 / 6 / 0 / 2 / 9 /
0 1 2 ... 10 11 12 13 14 15 16 17 18 19
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.
can someone help me with this?

September 8th, 2013, 02:56 AM
#2
Re: can someone help me?
so what is the problem that you are facing?
This is fairly simple and straightforward, given that the solution is already laid out for you  arrays.
Do you have any code to show for your efforts towards solving this?

September 8th, 2013, 05:08 AM
#3
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
Array2 (int2)
/ 1 / 2 / 3 / 4 / 5 / 6 / 7 /
0 1 2 3 4 5 6
Sum
/ 2 / 4 / 6 / 8 / 10 / 12 / 14 /
0 1 2 3 4 5 6
SumArray = Sum
/ 2 / 4 / 6 / 8 / 10 / 12 / 14 /
0 1 2 3 4 5 6
is this correct?

September 8th, 2013, 05:28 AM
#4
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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only  not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums  and not via private messages!
C++17 Compiler: Microsoft VS2017 (15.6.3)

September 8th, 2013, 05:41 AM
#5
Re: can someone help me?
can you give me some reference to study with... i really don't understand.

September 8th, 2013, 07:00 AM
#6
Re: can someone help me?
Originally Posted by kael6590
can you give me some reference to study with... i really don't understand.
http://en.wikipedia.org/wiki/Arbitra...ion_arithmetic
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only  not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums  and not via private messages!
C++17 Compiler: Microsoft VS2017 (15.6.3)

September 8th, 2013, 08:43 AM
#7
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.
Last edited by ShaQ.Blogs; September 8th, 2013 at 08:59 AM.

September 9th, 2013, 06:24 PM
#8
Re: can someone help me?
Originally Posted by kael6590
the problem of adding two large positive integers
Well, I guess this is a newbie programming task and the addition algorithm you're supposed to be using is the one you were taught in first grade school on paper .

October 6th, 2013, 11:12 AM
#9
Re: can someone help me?
can you help me fix this error ? pls
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
OnDemand Webinars (sponsored)
