Which are the values in arr after execution of following.. Int[]arr={1,1,0,0,0}; for(int i=2;i < arr.length;i++) arr[i]=arr[i-1]+arr[i-2];

  1. 1.11011

  2. 2.1121

  3. 3.11222

  4. 4.11235

  5. 5.11248


Correct Option: D

AI Explanation

To determine the values in the array arr after executing the given code, let's go through each iteration of the loop:

  1. Before the loop starts: arr = [1, 1, 0, 0, 0]
  2. Iteration 1: arr[2] = arr[1] + arr[0], so arr[2] = 1 + 1 = 2 Updated arr = [1, 1, 2, 0, 0]
  3. Iteration 2: arr[3] = arr[2] + arr[1], so arr[3] = 2 + 1 = 3 Updated arr = [1, 1, 2, 3, 0]
  4. Iteration 3: arr[4] = arr[3] + arr[2], so arr[4] = 3 + 2 = 5 Updated arr = [1, 1, 2, 3, 5]

After executing the code, the final value of arr is [1, 1, 2, 3, 5].

Among the given options, the correct answer is D) 4.11235, as it matches the final values of the array arr.

Find more quizzes: