Re: how to add two no. of 100 digits or more?
- From: Tim Smith <reply_in_group@xxxxxxxxxxxxxxxx>
- Date: Wed, 30 May 2007 22:10:59 -0700
In article <1180511603.131286.56600@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Umesh <fraternitydisposal@xxxxxxxxx> wrote:
Is there any way by which i can do it? Thanks.
Yes. You do it the same way you would do it by hand on paper. The main
difference is that it might be more convenient to work in something
other than base 10, depending on exactly how you have the numbers
represented.
If *all* you need to do is add numbers, this is sufficient. It will be
easy to implement, and the time complexity will be O(N), where N is the
number of digits in the larger number, and that is the best you can do,
so no need to use an arbitrary precision library.
However, if you need to multiple or divide numbers with 100 digits or
more, then do as others have said, and find an arbitrary precision
library that looks good to you and use it. While you can reasonably
implement multiplication on your own following the common by-hand
algorithm, that's O(N^2) to multiply two N digit numbers, and that is
considerably slower than what you can do, but getting better involves
things not for the feint of heart. (I left subtraction out...it's not
really much different from addition, but you can blow it, so it can go
either way as to whether doing it yourself or using a library is best if
all you need is addition and subtraction).
See Knuth volume 2 for the details. (If possible, see all editions of
Knuth volume 2, because there were major changes to that part of the
book between the first edition, the second edition, and the third
edition. I think the second edition is the best if you want to
understand this area, rather than just copy an algorithm out of the
book).
--
--Tim Smith
.
- References:
- how to add two no. of 100 digits or more?
- From: Umesh
- how to add two no. of 100 digits or more?
- Prev by Date: Re: accessing physical memory mapped to a pci board
- Next by Date: Time and date
- Previous by thread: Re: how to add two no. of 100 digits or more?
- Next by thread: how to replace a string by other string in a text file?
- Index(es):
Relevant Pages
|