Skip to content

Instantly share code, notes, and snippets.

@enile8
Created March 20, 2013 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enile8/5208123 to your computer and use it in GitHub Desktop.
Save enile8/5208123 to your computer and use it in GitHub Desktop.
Some in class recursion examples.
#include <iostream>
using namespace std;
int myFactorial(int integer)
{
if(integer == 1)
return 1;
else
{
return (integer * (myFactorial(integer-1)));
}
}
void desend(int counter)
{
if(counter != 0)
{
cout << counter << "\n";
desend(--counter);
}
}
void ascend(int counter, int stop)
{
if(counter != stop)
{
cout << counter << "\n";
ascend(++counter, stop);
}
}
int main()
{
int fact = myFactorial(3);
cout << fact << "\n";
desend(5);
cout << "\n";
ascend(1,5);
cin.get();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment