hello everyone.I have a question.
I saw this question in a site and tried to solve this but I have no idea can you help me?


Write a recursive function (use no while loops or for loops) that prints all the elements of an array of integers, one per line. The parameters to the function should be A (The array) and n (the size of the array).(pseudocode )

>I saw this question in a site and tried to solve this but I have no idea can you help me?
If you tried, then show us your attempt and what you learned from the failure. This is pretty close to the easiest of recursive problems, so I'm inclined to think that you gave up far too easily, if you tried at all.

On a side note, this is an extremely poor use of recursion. Any kind of linear progression (or similar slowly decreasing problem sets) should be avoided in favor of iteration because the chance of stack overflow increases drastically when number of expected stack frames is potentially large.

post an attempt and someone will help you from there. Frequently recursive functions look something like this:

returnValueType functionName(list of function parameters)
  if this is the value to terminate the sequence of recursive calls
    stop
  otherwise
    do something either before or after the next call to this function
    increment some value and repeat the function call passing the incremented value instead of the old value

Therefore I think you need to pass a third parameter to the function, and that is the index of the current element of the array.

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.