3

Possible Duplicates:
“BigInt” in C?
How to implement big int in C++

How do we work with big numbers without making use of external libraries and functions?

Some problems are as follows:

What is the sum of the digits of the number 21000?

Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.

37107287533902102798797998220837590246510135740250
46376937677490009712648124896970078050417018260538
74324986199524741059474233309513058123726617309629
91942213363574161572522430563301811072406154908250
23067588207539346171171980310421047513778063246676
8926........................................771585
42502016545090413245809786882778948721859655517457
72107838435069186155435662884062257473692284509516
20849603980134001723930671666823555245252804609722
53503534226472524250874054075591789781264330331690

(this list goes on...)

How would you go on to solve such problems? What approach can I use?

Thanks in advance.

*by the way, these problems are taken from Project Euler but many other instances exist not only there. I found these just to provide an example.

jww
  • 97,681
  • 90
  • 411
  • 885
Murat Derya Özen
  • 2,154
  • 8
  • 31
  • 44
  • 2
    Possible duplicate http://stackoverflow.com/questions/117429/inputting-large-numbers-in-c – DumbCoder Jul 20 '10 at 13:05
  • 1
    Possible duplicate - http://stackoverflow.com/questions/238343/big-number-in-c – DumbCoder Jul 20 '10 at 13:05
  • 3
    There are some good suggestions in reply to [How to implement big int in C++](http://stackoverflow.com/questions/269268/how-to-implement-big-int-in-c). – James McNellis Jul 20 '10 at 13:05
  • If you want to avoid libraries and perform the multi-precision math yourself, then I suggest you take a look at Donald Knuth's [Art of Computer Programming](https://en.wikipedia.org/wiki/The_Art_of_Computer_Programming). I believe Volume II, Seminumerical Algorithms, Chapter 4, Multiple Precision Arithmetic, is what you are interested in. – jww Aug 29 '17 at 17:54

2 Answers2

4

You need GMP, the GNU multi-precision library. Seriously, don't re-invent the wheel.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
1

Build your bigint implementation, or download one.

Mau
  • 14,234
  • 2
  • 31
  • 52