In Project Euler, I've been trying to do two problems that appear to have numbers beyond the storing capacity of an int. The thing is that they require exact accuracy in order to correctly solve a problem. I've been thinking of using a string to store digit by digit in order to solve this. However, the part that I'm stumped at is how could I store/calculate such a number in the first place?
I was thinking of using the modulo of each digit and store it as a char to convert to a string.
I suppose you could do something like this in order to grab a digit:
or
Where x is the power or the where you would grab the digit, for example, in the hundred or thousand. However, it appears that when trying to solve a problem that involved grabbing digits from the thousands, I couldn't correctly formulate such.
So the question is what's the best approach to this? I don't want a posted code that can actually do it or an external library, as I wish to figure this out without using a 3rd party library. Procedures and advice is what I'm looking for.
I was thinking of using the modulo of each digit and store it as a char to convert to a string.
I suppose you could do something like this in order to grab a digit:
Code:
digit = number % 10^x; //Java
Code:
digit = number % pow(10,x); //C, C++, Objective-C
Where x is the power or the where you would grab the digit, for example, in the hundred or thousand. However, it appears that when trying to solve a problem that involved grabbing digits from the thousands, I couldn't correctly formulate such.
So the question is what's the best approach to this? I don't want a posted code that can actually do it or an external library, as I wish to figure this out without using a 3rd party library. Procedures and advice is what I'm looking for.