| apeachaday (38) | |||
I have a small recursive function I am trying to follow, but I'm just not getting it. I know if I put in the number 36, it returns 5. I did some calculations on paper, but I am obviously missing something because my answer doesn't match the function answer. Any help, tips, or suggestions are greatly appreciated!
| |||
|
|
|||
| LowestOne (768) | |
|
5 seems about right to me. The calls: 36 - is 36 < 2 no... F(18) 18 - is 18 < 2 no... F(9) 9 - is 9 < 2 no... F(4) (int division) 4 - is 4 < 2 no... F(2) 2 - is 2 < 2 no... F(1) 1 - is 1 < 2 yes... return 0 to F(2) return 1 to F(4) return 2 to F(9) return 3 to F(18) return 4 to F(36) return 5 to main() 5 is also the correct answer, as 2^5 <= 36 < 2^6 | |
|
Last edited on
|
|
| apeachaday (38) | |
| Thanks! I think I've got it now. | |
|
|
|