// This program demonstrates the use of recursion in coding // with the example of a function that finds a factorial of a number // Sasha Vassar Week09 Lecture 16 // Think of the example of factorials // 1! = 1 // 2! = 2 * 1 = 2 // 3! = 3 * 2 * 1 = 6 // 4! = 4 * 3 * 2 * 1 = 24 // 5! = 5 * 4 * 3 * 2 * 1 = 120 // So what do we think would be the stopping case? (n <= 1) // What about the recursive case? factorial = number * factorial(number-1) #include double factorial(double number); int main(void) { int number; printf("Enter a number to find factorial of: "); scanf("%d", &number); printf("The factorial of %d! is %lf\n", number, factorial(number)); return 0; } //Let's write our function! double factorial(double number) { //Stopping case if (number <= 1) { return 1; } else { // Recursive case return number * factorial(number-1); } }