Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to multiply thosand digit numbers without using bigint
Posted

You can do it in the same way multiplication is carried out manually.

There are only a view basic operations you'd need to implement.


  1. Adding two numbers. For simplicity you may want to start by using Strings as the representation using them in reverse digit order, i.e. the least significant digit is on the leftmost side. That way you you can work your way from the left of the string to the right without having to pad one string. You iterate over the characters in the shorter of both strings adding the numbers and keeping the carry for the next digit.
  2. Multiplying by ten: prepend a 0 to the string (remember we are having the reverse digit order)
  3. Multiplying by one: return the string (simples ain't it?)
  4. Multiply a string with a single digit
  5. Now you have all the basic parts that will allow you to multiply two arbitrary length strings of digits much the same way you learned to do manual multiplication in school.
  6. Final step before output: Reverse the string to get the digits into "natural order". :)


Regards,

— Manfred
 
Share this answer
 
Hi,

One approach that came to mind is convert those numbers into a string and then multiply each other using the Long multiplication algorithm:

http://en.wikipedia.org/wiki/Multiplication_algorithm[^]

Best regards,
Filipe Marques
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900