1. ## recursivity & iteration

Hi, im a novice c++ programmer and im having a bit of diff. understanding recursivity and iteration. Can anyone please give me a clear example. Is it possible to use iteration for a recursive problem? Im trying to figure out a way to solve towers of hanoi using iteration. Any links or help will be appreciated. Thanks

2. Have you tried googling 'towers of hanoi'?

I think the 'cut-the-knot' web site may have the explantion you're looking for. It explains the recursive solution, which is by far the easiest. It then explains the iteration formula and finally it explains the 'non-recursive' solution!

If this is h/w look into implementing the recursive solution. It's only a few lines of code.

Recursive just means calling a function from a function. For a more detailed explanation of recursion check out google.

3. Hi, im a novice c++ programmer and im having a bit of diff. understanding recursivity and iteration.
Hi,

Well, first things first: it's called "recursion" not recursivitytionabilityness.

Can anyone please give me a clear example.
Here's an easy one:
Code:
```#include <iostream>
using namespace std;

void recursive1(int n)
{
cout<<n<<endl;

if(n > 0) //ending condition
recursive1(n-1);
}

int main ()
{
recursive1(9);

return 0;
}```
Here's one that's a little trickier:
Code:
```#include <iostream>
using namespace std;

void recursive2(int n)
{
cout<<n<<endl;

if(n < 10) //ending condition
recursive1(n+1);

cout<<n<<endl;
}

int main ()
{
recursive2(5);

return 0;
}```