Hi im having trouble with this Lab I know it says you can choose any language to
ID: 3799212 • Letter: H
Question
Hi im having trouble with this Lab I know it says you can choose any language to use but since im studying java at the moment I would like to this to be done in java so i would be able to follow along and see what you are doing.
MATH 115 PROGRAMMING LAB is known that in the Fibonacci sequence, the ratio of consecutive terms approaches the golden ratio, which 1 V5 In this lab, you will experiment if sequences with is 618 different starting values but are otherwise "Fibonacci-like" will also have consecutive terms approaching the golden ratio. l, Write a program (you choose the language) which performs the following pseudocode. Begin Program Integer i, Integer array A(20): declare an integer array of size 20 A(1) 1; A(2) 1; first 2 numbers of Fibonacci sequence For i 3 to 20 or (for i 3; i 20; i++) A(i) 1-1) A(i-2); /1 recursive step Next i For i 1 to 20 Print A(i) print out array Next i Print "Ratio of 20th term to 19th term is"; Print A(20)A(19) End Program 2. Same thing but the starting numbers are A(1) 1 and A 2) 3. 3. Same thing but the starting numbers are A(1) 2 and A 2) 7. 5. Make a speculation about the ratio of consecutive terms of any Fibonacci-like sequence (as long as we don't start with A(1)-0 and A(2) 0.Explanation / Answer
/*1. Required solution in Java*/
public class Fibonacci {
public static void main(String[] args) {
int i;
int[] A = new int[20];
A[0] = 0;
A[1] = 0;
for (i = 2; i < 20; i++) {
A[i] = A[i - 1] + A[i - 2];
}
for (i = 0; i < 20; i++) {
System.out.println(A[i]);
}
System.out.println("Ratio of 20th term to 19th term is:");
System.out.println((double) A[19] / A[18]);
}
}
Required exceution cycle with different inputs.
/*
2. A[0] = 1 and A[1] = 1
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
Ratio of 20th term to 19th term is:
1.6180339631667064
3. A[0] = 1 and A[1] = 3
1
3
4
7
11
18
29
47
76
123
199
322
521
843
1364
2207
3571
5778
9349
15127
Ratio of 20th term to 19th term is:
1.6180340143330838
4. A[0] = 2 and A[1] = 7
2
7
9
16
25
41
66
107
173
280
453
733
1186
1919
3105
5024
8129
13153
21282
34435
Ratio of 20th term to 19th term is:
1.6180340193590828
5. A[0] = 0 and A[1] = 0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Ratio of 20th term to 19th term is:
NaN
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.