Complete the code to make the factorial function call itself recursively.
int Factorial(int n) {
if (n == 0) return 1;
return n * Factorial([1]);
}The factorial function calls itself with n - 1 to reduce the problem size until it reaches 0.
Complete the code to correctly calculate the sum of numbers from 1 to n using recursion.
int Sum(int n) {
if (n == 1) return 1;
return n + Sum([1]);
}The function sums numbers by adding n to the sum of numbers from 1 to n-1.
Fix the error in the recursive Fibonacci function call.
int Fibonacci(int n) {
if (n <= 1) return n;
return Fibonacci([1]) + Fibonacci(n - 2);
}The Fibonacci function calls itself with n - 1 and n - 2 to get the two previous numbers.
Fill both blanks to complete the recursive function that prints numbers from n down to 1.
void PrintDescending(int n) {
if (n == 0) return;
Console.WriteLine([1]);
PrintDescending([2]);
}The function prints n, then calls itself with n-1 to print the next smaller number.
Fill all three blanks to complete the recursive function that calculates the power of a number.
int Power(int baseNum, int exponent) {
if (exponent == 0) return [1];
return baseNum * Power(baseNum, [2]);
}
// Example call: Power(2, 3) returns [3]Power of any number to 0 is 1. The recursive call reduces exponent by 1. 2 to the power 3 is 8.
