OP,
Here are some suggestions as to storing the number.
*
Store a decimal digit in one char variable.
This is the easiest way , totally inefficient but if you want to do very few calculations and don't want to use a library , go for this way.
Arithematics is much easier this way , just add , subtract the corresponding digits with carry.
Multiplication can be done just like the way we are taught in schools.
42
x 21
-----
42
81X
-----
852
|
Converting to a string is straightforward , for each digit , add char('0'+digit) to the string.
*
Store ⌊log10(28*sizeof(std::size_t))⌋ digits in one std::size_t variable.
In this format , you store the maximum possible number of digits in a word.
e.g. if sizeof(size_t) is 4 , you store ⌊log
10(2
8*4)⌋ = 9 digits per word.
Operations similar to above but we have a word at a time than digit.
When you convert to string , add each digit from a word by taking char('0'+ word (mod 10) ) , then divide by 10 in each iteration. But , remember to add padding zeroes.
*
Store in binary format.
This is the way libraries like GMP et al. store numbers internally.Not Recommended.