Hi. sorry on my bad english, but I'm not an English speaker.
I'm a computer student, learning for bachelor's degree.
I have a task, and i've no idea how to deal with it.
The mission is quite simple and goes like this:
I need to write down a recursive function that get a number and return this number - but reverse.
The function should return the number - not print it.
Example: The program run, and ask a value for x.
the user entered 58753 into x.
The function should return x as 35785.
Now, I've success to build such one, but with golbal variables. I asked the course guide, but he told me that I've mustn't use global variables, either not loops.
I've running out of ideas...
Any help?



LinkBack URL
About LinkBacks



If you need a temporary variable that persists between recursive calls, you can pass the initial value to the first call, modify it within the function, then pass it again when you call the function recursively. With that scratch variable, it's trivial to convert a loop based algorithm like this into a recursive one.