How can we store a very large number in c or c++ ?
For example to calculate 99! (contains about 150 digits), how to do this in efficient manner ?
@hmtupd123 You can use BIG INTEGERS in C++ using boost library.
Here is an implementation of BIG INTEGERS in C++ using boost library (link).
For storing such large numbers you have to make use of the arrays or vectors which are containers that can store such large values … and the number may pe interpreted as the digits seperated in different cells of the array.
You can’t store such a big number in any of the data types available in C or C++ but even if you want to store the value of say 99! or even 100! then have a look at this blog post of CodeChef.
You have to use array to store such a large number.you can see the codechef tutorial for small factorial (FCTRL2).it is already discussed there.So I don’t think i should repeat it here .you can easily check that tutorial.Or you can easily google small factorial codechef…you will get appropriate results.Here is the link
Happy Coding:).
I would suggest you to move to Java for this specific problem due to the availability of BigInteger.
However , in C/C++, I would suggest you to read the implementation of BigInteger, and write something similar in C++, supporting only the operations that are common.
Hi.
The best answer to your question would be the blog post on codechef: https://discuss.codechef.com/questions/7349/computing-factorials-of-a-huge-number-in-cc-a-tutorial
maybe u should use string or array in this case u can handle even larger than what you are talking here.
you should use an array or string .you can handle even bigger than you are talking.