For this practice problem even if it's simple do them anyway you might surprise yourself
this will be a recursion practice problem
make the Fibonacci sequence using recursion (1+1 =2, 2+1 = 3, 3+2 = 5, 5+3 = 8, 8+5 = 13) you get the idea. do it however you want you could ask a user how many numbers you want in the sequence or just give a set number or make your own starting sequence do a countdown sequence it doesn't matter so long as you can get the recursion to do what you want it to do. If you don't know what recursion is it is where you keep calling the same function over and over. So if you don't have a way to stop it, it would cause a stack overflow error(a infinite loop)
good luck and please post your results I would like to see what ideas you all have in mind. I will post mine after a few are posted to help you use your creativity.
After doing it with recursion see what other ways you can make the Fibonacci sequence work
post them as well
Good luck
EDIT: Ok I put a little example of what recursion looks like. I'm sure somebody better could make it even tighter looking but hey I'm a noob still too
- Code: Select all
#include <iostream>
int recursion(int countdown);
int main()
{
int counter = 10;
recursion(counter);
std::cout<< "Blast off\n";
}
int recursion(int countdown)
{
if (countdown == 0)
{
return 1;
}
std::cout<< countdown << "\n\n\n";
return recursion(countdown - 1);
}
you may notice I don't put in anything to keep it from diapering after it's run. I use visual studios so I just always run my programs with (ctrl + F5) does the same thing as if you have system pause
