/* recurse.cpp CIS 250 Dave Klick 4/4/05 Demonstration of recursion done in class. */ #include using std::cout; using std::endl; long fact(long n) { if (n < 2 ) return 1; else return n * fact(n-1); } long fib(long n) { if (n < 2) return n; else return fib(n-1) + fib(n-2); } void reverse(char* p) { if (*(p+1) != '\0') reverse(p+1); if (*p != '\0') cout << *p; } int main(void) { cout << fact(5) << endl; cout << fact(6) << endl; for (long i=0; i<20; i++) cout << i << ": " << fib(i) << endl; char* msg = "Recursion is fun!"; reverse(msg); cout << endl; return 0; }