Tell me more ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

This is a question on my homework could you help me figure it out?

Write a non-recursive procedure that takes an array and its length and prints its elements in the reverse order. For example, if the array has elements 77, 12, 90, 34, 45, the procedure should print the values 45, 34, 90, 12, 77. Here is the header for the procedure: Procedure printReverse(array[], length)

share|improve this question
3  
This would do much better on StackExchange - there's essentially no element of this question that involves mathematics. – Steven Stadnicki Dec 16 '10 at 0:29
5  
@Steven: StackOverflow, you mean. ;) – J. M. Dec 16 '10 at 0:33
So THIS is where all of the terrible questions on StackOverflow originate! – Eric Mickelsen Dec 16 '10 at 4:59
4  
That's a bit unfair, @Eric, – J. M. Dec 16 '10 at 6:25

closed as off topic by J. M., Ross Millikan, Gone, Aryabhata, Arturo Magidin Dec 16 '10 at 3:57

Questions on Mathematics Stack Exchange are expected to relate to math within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

2 Answers

Ross is correct. Remember that a recursive function is one that calls itself. Writing a for loop as follows involves no such recursion:

for(int i = length - 1; i >= 0; i--) cout << array[i] << " ";

share|improve this answer
1  
@Ross: Since I can't comment on other posts yet, my code is in C++. Also, I didn't really understand NEWprogrammer's objection to your pseudocode answer so I thought I'd formally write it out in a programming language to show that no recursion was used. – Jason Dec 16 '10 at 1:34

Can you just print array[i] for i counting down from length to 1? Python can do it in one line.

share|improve this answer
its supposed to be in psuedo code which should be easy but it isnt – NEWprogrammer Dec 16 '10 at 0:27
I would have called mine pseudocode as it is not in any specific language, while Jason's looks like proper C (but I can't be sure). – Ross Millikan Dec 16 '10 at 1:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.