Create a class with a method that calls itself to calculate the number of ways a person could climb a staircase of n steps if they can take 1 step at a time, 3 steps at a time, 5 steps at a time, or any combination thereof. Allow the user to specifiy the number of steps n. Assume at the top of the stairs there is a flat surface so it doesn't matter if the user oversteps on their last step.
I can think of how to do this if I were to set up while()s inside of while()s infinitely, but I don't know how to set it up in a recursive manner. I understand what recursion is, but I don't know what algorithm should be used for this problem.
Question
MacemanD
I can think of how to do this if I were to set up while()s inside of while()s infinitely, but I don't know how to set it up in a recursive manner. I understand what recursion is, but I don't know what algorithm should be used for this problem.
Any help is appreciated.
Link to comment
Share on other sites
14 answers to this question
Recommended Posts