Starting from:
$30

$24

Homework 7 Solution

Files to submit: foo.c

Time it took Matthew to Complete: 10 mins




All programs must compile without warnings when using the -Wall and -Werror options
Submit only the files requested

Do NOT submit folders or compressed files such as .zip, .rar, .tar, .targz, etc
Your program must match the output exactly to receive credit.

Make sure that all prompts and output match mine exactly.
Easiest way to do this is to copy and paste them
All input will be valid unless stated otherwise
Print all real numbers to two decimal places unless otherwise stated
The examples provided in the prompts do not represent all possible input you can receive.
All inputs in the examples in the prompt are underlined

You don't have to make anything underlined it is just there to help you differentiate between what you are supposed to print and what is being given to your program
If you have questions please post them on Piazza



Restrictions




No global variables are allowed
Your main function may only declare variables, call other functions, and assign variables values.
You must solve this problem recursively
You may only make ONE recursive call in the recursive case
For this assignment you will be writing a program to calculate the value of the function foo. The value of foo is defined as follows

foo(0)=2

foo(1)=3

foo(2)=5




foo(n)= foo(n−1)+ foo(n−2)+ foo(n−3)




Specifications




The value of n is accepted through the command line



You may only make 1 recursive call in the recursive case
1. If you don't you will fail many of the tests with a timeout issue

You must solve the problem recursively



Example




1. ./foo.out 2

foo(2) = 5

2. ./foo.out 10

foo(10) = 697

More products