1. Consider the Fibonacci sequence. (Fibonacci sequence starts from 1. Please in
ID: 3856804 • Letter: 1
Question
1. Consider the Fibonacci sequence. (Fibonacci sequence starts from 1. Please include both the codes and the OUTPUT)
(1). Write a ‘for’ loop to generate the Fibonacci sequence, and print out the rst ten terms;
(2). Derive a closed form for the Fibonacci sequence(You just write your nal results into word document, and no steps are needed);
(3). Create a vector bProd where each element of bProd is the product of two consecutive Fibonacci numbers;
(4). Create a vector partialSum where each element partialSum is a partial sum of the sequence of squares of Fibonacci numbers; Do you observe some-thing comparing (3) and (4)?
(5). Create a vector r where each element r is the ratio of consecutive Fi-bonacci numbers: r = [f0/f1 f1/f2 · · · fn1/fn]. What do you notice about the elements of r?
Explanation / Answer
A ‘for’ loop to generate the Fibonacci sequence, and print out the rst ten terms;-
int a=1;
int b=1;
int c;
int count=10; // To generate the Fibonacci Series upto the first ten terms
System.out.print(a+" "+b);
for(int i=2;i<count;i++)
{
c = a + b;
System.out.print(" "+c);
a = b;
b = c;
}
Output:-
1 1 2 3 5 8 13 21 34 55
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.