Hello, I need to write a program that finds the digits of an integer with a maximum size of 10^100. I understand all the algorithms, but I can only use them with regular integers with my current knowledge, I tried using long int, but this represented the numbers like this: 1.e+100
What type should I use? (I hope this is type that I am talking about here, it's different in my native language)
How do I get the number in a format in which I can find the value of each digit?
I am not sure what you're trying to ask. Do you want to count how many digits are in a number? For example, 100 has 3 digits? Or are you trying to do something else?
No, I need to find them. for an example, the digits of 123456789 are 1, 2, 3, 4, 5, 6, 7 ,8, 9
I know how to do this with any regular integer, I just don't know how to do it on a long one, in my case, an integer that would have a size between 0 and 10^20
Please explain your problem better.
Do you want to search the larger for a smaller string of numbers ?
Is your 10^20 number stored in a file ?
If so is the file a text file ?
do you just need to know if a match is found or is there something else you plan to do?
OP's question clearly pegs him as a very confused beginner, so smug answers don't help much. How about something like:
Use long int or long long int. An integer will never print as 1.e+100. Only floating point values will. Make sure you don't convert your value to a float or double.
The trick with this (very common) assignment is to understand:
- basic arithmetic operations on integers (division and remainder)
- loops
To separate out the least-significant (rightmost) digit from a number, use remainder of division by ten: r = x % 10;
To then remove that digit from the number, use division by ten: x = x / 10;
Put that stuff in a loop. Can you see when the loop should stop?
OP's question clearly pegs him as a very confused beginner, so smug answers don't help much. How about something like:
For the benefit of Duoas:
c4l wrote:
I need to write a program that finds the digits of an integer with a maximum size of 10^100.
...
I know how to do this with any regular integer, I just don't know how to do it on a long one
@OP:
I would, again, direct you towards processing the number as a string. Some of us aren't so smug as to think we can answer a question without reading it.
I know how to do this with any regular integer, I just don't know how to do it on a long one, in my case, an integer that would have a size between 0 and 10^20
I'm not that smug either. OP is making up value ranges.
If his number really does contain 20 to 100 digits, then yes, processing it as a string the only option he has.
I admit I was responding more to the "prof is an idiot". Sorry.