Re: multiplication



On 30 Apr 2007 04:29:26 -0700, helPlease <devlinahello2@xxxxxxxxx>
wrote:

I want to multiply two very long integers (say of 20 digits).I am
storing them in character array.Then what mechanism should i follow
to mutiply two such numbers.If anybody has any suggestions please post.

Take a pencil and paper and multiply two four-digit numbers. Carefully
show **every** step. Notice that while the total number of steps is
dependent on the number of digits in the two numbers, each individual
step is dependent only on one digit from each number (and any
potential carry from the previous step).

As a preliminary step to multiplying, work out the algorithm to add
two numbers of arbitrary length. Then implement the algorithm in a
function and test extensively. Notice that the sum of two n-digit
numbers has at most n+1 digits.

Follow the same process for multiplication. Since you will need to do
some addition, make use of the function previously developed. Notice
that the product of two n-digit numbers can have up to 2n digits.

If/when you run into problems, post your code and ask specific
questions. Here is a starting hint. Decide if the elements of your
character array will contain the integer value or the character value
of the digits, '1' is not the same as 1. One simplifies input/output;
the other simplifies computation.

And please don't post the same question multiple times with different
subjects.


Remove del for email
.



Relevant Pages

  • Re: Assembly Language - Mathematics WITHOUT maths coprocessor
    ... The way we were taught to do this was to convert 1.2 to an integer, by multiplying it by 10 enough times to do so. ... The same is true with the denominator, which also needs to be "* 10" for it to all work out, but it's already "* 10" because it's in fixed point format, so we don't do anything to it. ... If character is a number, multiply x by 10 and then add that number. ... This is because so many of those digits aren't even going to make it into the final number that the error caused by not doing so is very very very small. ...
    (alt.lang.asm)
  • Re: Invariant with DIGIT-CHAR-P and the reader.
    ... The current situation in CLISP allows users to parse Unicode text ... either ASCII, some sort of ISO-Latin, or Unicode and this will work ... because the digits are probably located identically. ... But, strictly, there is no requirement at all that the ASCII character ...
    (comp.lang.lisp)
  • This is soooo kool!
    ... letters and the number that are digits. ... character of actual, useful information. ... Microsoft once used a 7 digit key, whose checksum was ... Does anybody know if there are any key calculation algorithms *not* based ...
    (sci.crypt)
  • Re: [PHP] Removing commas from number
    ... I had earlier assumed that you were supplying the same numeric value to two output destinations -- display and SQL. ... I don't think a good input validation routine would simply delete any non-numeric character from the input. ... Note that different cultures have very different ways of expressing numbers -- comma for the decimal point and period for the thousands separator, different numbers of digits between separators, and different characters mixed with the digits to indicate scale. ...
    (php.general)
  • Re: Arithmetic - Multiply & Divide vs * & /
    ... > exceeded, which is apparently 15 digits in your case. ... > |Decor Decto match the field it's multiplying. ... > |Any should I always be using Multiply and Divide fctns, ... > of digits after the point, it's generally necessary to use DIVIDE. ...
    (comp.lang.pl1)