So far, so good. But it would be better to split the number into the ones digit and the rest. You know how to deal with the ones digit. Deal with the rest recursively. Then figure out how to put the two pieces together again.Originally posted by Dave DiRito:
I can get the ones digit to double by using i = i*10 + i%10;
I don't know how to proceed from there.
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Enter a number for Double Digits: 147
q = 14
ones = 7
result before call = 77
q = 1
ones = 4
result before call = 44
q = 0
ones = 1
result before call = 11
0
q at 0, num at 0
num = 11
num = 44
num = 77
Originally posted by Dave DiRito:
Sorry to be so dense about this. I greatly appreciate everyone's help walking me through it.
From Garrett's post I see the pattern that to turn the ones into double digits you multiply it by 11, the tens digit becomes a ten thousand number by multiplying by 1100, the hundreds digit becomes a hundred thousand number by multiplying by 110,000. So, I must need some kind of log function like Piet just posted or something to raise 11 to some power of 10 based on the size of the number that's passed into the method. Is that what I need?
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
If you find it difficult, read Garrett Rowe's last post backwards. Recursion may be easier to understand backwards.Originally posted by Garrett Rowe:
Can you see the recursion in that kind of algorithm?
So you have one or two more lines of code to write.I'll deal with negative integers after I get this working correctly.
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|