Add code to the following so that when the program finishes the array named fibs
ID: 3830592 • Letter: A
Question
Add code to the following so that when the program finishes the array named fibs will contain the first 1.000 Fibonacci numbers. What are the Fibonacci numbers? The first Fibonacci number is 0. The second is 1. All the rest are the sum of the prior two, so the third Fibonacci number is 1 (0 + 1 = 1). The fourth 2 (1 + 1 = 2). The fifth is 3(2 + 1 = 3), etc. In other words: Fibonacci (0) = 0 Fibonacci(1) = 1 Fibonacci (n) = Fibonacci(n - 1) + Fibonacci(n - 2) You should set things up so that Fibonacci(0) is stored in slot 0 array, Fibonacci(1) is stored in slot 1, etc. using System;//this program is legal, but oddly indented {Class Program {static void Main(string [] args) {int [] fibs = new int [1000];//array to store Fibonacci numbers in//At this point, fibs [0] == 0, fibs [1] == 1, }}}//fibs[2] == 1, fibs [3] == 2, etc, etcExplanation / Answer
FibonacciNos.java
package org.students;
public class FibonacciNos {
public static void main(String[] args) {
int[] fibs = new int[1000];
fibs[0] = 0;
fibs[1] = 1;
/* This for loop will generate the fibonacci Numbers
* and populate those into fibs[] array
*/
for (int i = 2; i < fibs.length; i++) {
fibs[i] = fibs[i - 2] + fibs[i - 1];
}
}
}
___________________Thank You
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.