-19

Let's say we have a really, really, big number (a hundred thousand digits or more)

We can store this number in java using "Bigint" but I don't know how we could do this in C++. How can we store a number this large in C++?

AndyG
  • 38,029
  • 8
  • 100
  • 134
Crew HaXor
  • 573
  • 1
  • 6
  • 16
  • 2
    What do you need to do with it other than store it? You could store it as a string, if it doesn't have to be used as a number. – Ryan Lundy Feb 07 '14 at 22:40
  • 1
    Storing it is trivial - just use a string. The much better question to ask is what types of operations are you doing on this data and what types of data types are required to support those operations? Dealing with "Very large" numbers requires specialized libraries, and there area number of those available. – Chris M. Feb 07 '14 at 22:41
  • 5
    I don't think quoting the **exact** number contributes anything to the question ;) – user2802841 Feb 07 '14 at 22:42
  • Quoting the exact number does actually help. It's the string of digits for the Project Euler #8 problem. @user3285778, you could use a BigNum library but in this case you can solve the problem easily by leaving it as a single character string and just looking at 5-character-long substrings. – Blastfurnace Feb 08 '14 at 00:03

1 Answers1

2

You have to use bignum arithmetic which isn't included in standard C++ library so you either have to write it yourself or use some third party library.

About storing specifically - well it could be stored as an array (or vector) of unsigned ints less than 10000 for example which will represent it's numbers "digits" by base 10000. There could be a lot of other ways though depending on exact arithmetic implementation.

Predelnik
  • 4,893
  • 2
  • 23
  • 36