1. ## Recursive function

I am still learning this. Does this look right?
Thanks!!
Code:
```
Void DoIt(int N) {
if ( N > 0) {
cout << N << " ";
DoIt(N + 1);
}
}``` 2. *looks around*

what's it supposed to do? looks to me that if you put in any value >=1, it'll loop forever till the stack overflows, anything <1 won't even be displayed. 3. I am just supposed to write a recursive function, just not sure if this is "good" or not. If it was in a program would it work? 4. it would work, but forever(or a crash)  5. The function works fine, it recursively calls itself. However, you either a) put the limit in the wrong direction or b) forgot to put a limit in there.

If you don't have a limit in the function it will keep calling itself until your program crashes. I'd suggest putting something like if(N>=50) return; in there or something so that it stops at 50 6. You could also change this:
Code:
`DoIt(N + 1);`
to this:
Code:
`DoIt(N - 1);`
Then, if you pass in any number it will print a countdown to 1. 7. why not create a more useful recursive function... try writing something similar to the pow() function...

Code:
```long double pow(int base,int exp)
{
if(exp==0)
return 1;
else if (exp>1)
//recursiveness goes here
else
//you figure out what goes here
}```
fill in the blanks... Popular pages Recent additions 