CSC 273 - Data Structures

Assignment #6 - Running the Recursive Fibonacci Function

Due Wednesday, October 2, 2019

A recursive function to calculate the nth Fibonacci number appears below. Insert statements before both return statements to print out both the parameter and the result.

int fib(int n)
{
  int	result;
  
  if (n <= 1)
    return(n);
  else  {
    result = fib(n-1) + fib(n-2);
    return(result);
  }
}

Then write a main program that uses the function to calculate the 4th Fibonacci number, i.e., n = 6. You will submit a program listing (properly commented) and your output.

[Back to the Assignments Page]