1. Call Tree The Fibonacci sequence is 0 1 1 2 3 5 8 13 21 ... Each Fibonacci nu
ID: 3668397 • Letter: 1
Question
1. Call Tree
The Fibonacci sequence is
0 1 1 2 3 5 8 13 21 ...
Each Fibonacci number is the sum of the preceding two Fibonacci numbers. The sequence starts with the first two Fibonacci numbers, and is defined recursively as
fib(0) = 0
fib(1) = 1
fib(n) = fib(n - 1) + fib(n - 2) for n > 1
Draw the call tree for fib(4) b) fib(3) c) fib (5)
2.
write a function
int maximum (int list[], int n)
that recursively finds the largest integer between list[0] and list[n] assume at least one element is in the list. test it with a main program that takes as input an integer count followed by values. output the original values followed by the maximum. do not use a loop in maximum. output the value in the main program, not in the function.
sample input
5 50 30 90 20 80
sample output
original list : 50 30 90 20 80
largest value :90
c++ or java
Explanation / Answer
# include <iostream>
using namespace std;
int max(int[], int);
int main ()
{
int list[40];
int number_size=0;
cout << "How many number would u like to enter ";
cin >> number_size;
for(int i=0; i<number_size;i++)
cin >> list[i];
cout << "original list: " << endl;
for(int i=0; i<number_size; i++);
cout << list[i] << endl;
cout << "largest value: " << max(list, number_size) << endl;
system ("pause");
return 0;
}
int max(int l[], int n)
{
static int count=0;
static int maximum=l[0];
if (maximum<l[count])
maximum=l[count];
count++;
if (count==n)
return maximum;
return max(l,n);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.