I need to write a recursive function reverseInput that until the user enters zero it keeps on accepting numbers, then when done, outputs them in reverse order. Only thing, i cannot use strings or arrays or anything of the like and it must be done in one recursive function. It should work like this:
enter a number:2
enter a number:53
enter a number:0
the numbers you have entered in reverse:53,2
I'm stumped again
jray344
0
Newbie Poster
Recommended Answers
Jump to PostThat's not hard to do, but you have to be very careful of getting stack overflow errors. And that's pretty each to do with recursive functions.
>>I'm stumped again
Do you know what a recursive function is? If not then read about them in your text book. Its simply …
Jump to Postvoid foo() { // ask for input // if input != 0 do recursion // print the number entered in this instance of the function and print a comma after it }
All 5 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
jray344
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
jray344
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.