0

Possible Duplicates:
how to sum a large number of float number?
“BigInt” in C?
handling integer having large number of digits

I want to sum two different number . think we have two different number that length of anyone is more than 20 number , how can I sum both ? as far as I know , I can not do this with int .

like these :

26565468416574156465651652464234245645945643526 + 6264635454513215421541412154121541544455412315

Community
  • 1
  • 1
Ata
  • 12,126
  • 19
  • 63
  • 97
  • You really need to provide an example with your question. It sounds like you are trying to use "big numbers" that are greater than 20 digits in size. – pickypg May 21 '11 at 18:06
  • 2
    possible duplicate of [how to sum a large number of float number?](http://stackoverflow.com/questions/2148149/how-to-sum-a-large-number-of-float-number) Also see: [handling integer having large number of digits](http://stackoverflow.com/questions/1559737/handling-integer-having-large-number-of-digits). – Cody Gray - on strike May 21 '11 at 18:07

4 Answers4

1

There is a bunch of libraries that can do this as well as you may implement it yourself. Check this Wikipedia article.

Yuri Stuken
  • 12,820
  • 1
  • 26
  • 23
1

Take a look at this C++ Big Integer lib

snoofkin
  • 8,725
  • 14
  • 49
  • 86
0

You must use some BigInteger implementation. Either search for a C++ library that does that or implement it yourself. Most common implementations store the "big integer" in an array of bytes. To add two of those, do a byte-wise addition and take care of carry (both generate and properate).

EDIT: Not necessarily bytes. Any unsigned storage like int32, int64 or whatever your machine can handle.

Hyperboreus
  • 31,997
  • 9
  • 47
  • 87
0

Miracl is a great solution and pretty standard solution :

http://www.shamus.ie/index.php?page=Downloads

Spyros
  • 46,820
  • 25
  • 86
  • 129