// This program demonstrates the use of recursion to create // functions with the example of a fibonacci sequence // Sasha Vassar Week09 Lecture 16 // Think of the example of fibonacci numbers, where each number // is the sum of the previous two numbers. // So sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21.... // So what do we think would be the stopping case? == 0 return 0; // What about the recursive case? #include int fibonacci(int number); int main(void) { int number; printf("Enter fibonacci number: "); scanf("%d", &number); printf("fibonacci(%d) is %d\n", number, fibonacci(number)); return 0; } //Let's write our function! int fibonacci(int number) { //Stopping case if (number == 0) { return 0; } else if (number == 1) { return 1; } else { // Recursive case return fibonacci(number-1) + fibonacci(number-2); } }