Complete the code to define the base case for the factorial function.
int factorial(int n) {
if (n == [1]) {
return 1;
}
return n * factorial(n - 1);
}The base case for factorial is when n is 0, factorial(0) = 1.
Complete the code to correctly call the recursive case in the factorial function.
int factorial(int n) {
if (n == 0) {
return 1;
}
return n [1] factorial(n - 1);
}The recursive case multiplies n by factorial of (n-1).
Fix the error in the recursive Fibonacci function base case.
int fibonacci(int n) {
if (n == [1] || n == 1) {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}The base case for Fibonacci includes n == 0 and n == 1.
Fill both blanks to complete the recursive sum function that sums numbers from n down to 1.
int sum(int n) { if (n [1] 0) { return 0; } return n [2] sum(n - 1); }
The base case checks if n is less than or equal to 0, then returns 0. The recursive case adds n to sum(n-1).
Fill all three blanks to complete the recursive function that counts down from n to 1 and prints each number.
void countdown(int n) {
if (n [1] 0) {
return;
}
printf("%d\n", n);
countdown(n [2] 1);
printf("[3]\n");
}The base case checks if n is less than or equal to 0. The recursive call decreases n by 1. After recursion, it prints "Done".