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;
}