Question: Figure 13.12 in the text contains a C program with a nested for loop. A. Mathematically state the series that this program calculates (that is,
Figure 13.12 in the text contains a C program with a nested for loop. A. Mathematically state the series that this program calculates (that is, write the equation for the quantity computed using mathematical symbols). Hint: The first several values of the summation are given in table . Table 2: First several values given by the program of Patt and Patel figure 13.12. B. Write a subroutine to calculate the following function: f(n)=f(n1)+f(n2) with the following initial conditions, f(0)=1,f(1)=1. - Turn in your code (written by hand is OK, no need to demonstrate routine and no Eval sheet.) - Your subroutine must take n as an integer input, and return f(n) as an integer output. - For full credit, the function declaration must be correct. Hint: Consider using integer variables Fn,Fminus_1 and Fminus_2, and, when needed, a for-loop starting with n=2. C. Extra Credit, (10 points). Consider that a C function can call itself (thorough the workings of the stack frame! (I would say "magic of the stack frame," but Patt and Patel say: "No Magic!", and they're right, you know enough about stack frames to see how C functions can do this.)) Implement a function that calls itself to compute f(n). Somewhere in your function could be the line int Calc_f_n(int n)1 Fn= Calc_f_n(n-1) + Calc_f_n(n-2); 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
