recursive to iteration

How do I frame the code so that it displays correctly indented. How can I make this execute as an iteration: iterative_countdown
<#include <iostream>
using namespace std;

void recursive_countdown(int count)
{
if (count == 0)
cout << "count=" << count << endl;
else
{
cout << "count=" << count << endl;
recursive_countdown(--count);
}
}

int main(void)
{
int count = 10;

recursive_countdown(count);

return 0;
}>

Last edited on
Do you know the difference between them? If so, you will know that you will need to use a loop (while / for) to achieve the same result as recursion.

In this case, the function is called again if count > 0, so why not try that?

Note: return should still be used within the void function.
Topic archived. No new replies allowed.