Recursion The double factorial of an odd number n is given by: Ex: The double factorial of the number 9 is: Write a recursive function called OddDoubleFactorial that accepts a scalar integer input, N, and outputs the double factorial of N. The input to the function will always be an odd integer value. Each time the function assigns a value to the output variable, the value should be saved in 8-digit ASCII format to the data file recursion_check.dat. The -append option should be used so the file is not overwritten with each save. Ex: If the output variable is Result then, the command is: save recursion_check.dat Result -ascii -append The test suite will examine this file to check the stack and ensure the problem was solved using recursion.

Respuesta :

Answer:

function Result = OddDoubleFactorial(n)

   % computes the double factorial of n using recursion

 

   if n == 1

       % save 1 as result if n is 1

       Result = 1;

   else

       % recursive call to the function

       Result = n * OddDoubleFactorial(n - 2);

   end

 

   % save the Result in a file

   save recursion_check.dat Result -ascii -append

end