+ 4
Storing and printing an integer value with 20 or more digits
how to do this?
5 ответов
+ 12
There is a concept of big integer that can handle any number of digits. There are a few library floating around in C++ or you could write your own. Personally, I'd write my own as it would be nice challenge.
+ 3
@Jayden LeCorps
There are two methods:
a) Strings that hold digits. This is the simple, but inefficient way.
b) pointers, bitwise operators and dynamic memory management using malloc. This is the efficient, but cancerous way.
It's a shame that the C++ language/standard library doesn't feature arbitrary length data types because, aside from that, it's really complete.
+ 3
@Jay Matthews
That would be a way to do it. And probably the best way if you don't want to get your hands dirty with bitwise.
But how do you calculate the carry-over of say 999,999,999*999,999,999? The only way I can think to do it is to make multiplication a for loop for repeated addition, and that's just not very efficient.
+ 2
thank you all for your help