SHORT ANSWER Assume the declaration: double x(8] = {10.0, 12.0, 8.0, 6.0, 2.5, 1
ID: 3559951 • Letter: S
Question
SHORT ANSWER
Assume the declaration:
double x(8] = {10.0, 12.0, 8.0, 6.0, 2.5, 14.0, 12.0, -5.0}; II initialized
Suppose that each of the boldfaced, lettered statements is executed in tum, so that each subsequent statement continues the processing of the preceding statement. Describe what each statement does to the array by showing the contents of the array x after each statement is executed. Assume thati is an int initially set to 2. Answer on this sheet, and submit it with the program listings and test output from Programs 1 to 3.
(A) x[i] = 2.0;
X (0) x[1] X (2) x[3] X (4) X (5) X (6) X (7)
(B) x[i] = x[i] + 5.0;
X (0] X (1] X (2] X (3) X (4] X (5] X (6) X (7]
(C) x[i-1] = x[2*i+l];
X (0] X (1] X (2] X (3] x[4] X (5) X (6) X (7)
(D) X [i+l] = X [2*i] + X [2*i+l] ;
X (0] X (1] X (2] X (3] x[4] X (5] X (6] X (7]
(E) for (i=2; i < 5; i++)
X [i] = X (i+l] i
X (0] X (1] X [2] X (3] X (4] X (5] X (6] X (7]
(F) for (i=3; i >= 0; i--)
X [i+l] = X (i] i
X (0] X [1] X (2] X (3] X (4] X (5] X (6] X (7]
Explanation / Answer
/*Code*/
Output:
x[0]=2.0 x[1]=2.0 x[2]=2.0 x[3]=2.0 x[4]=2.0 x[5]=2.0 x[6]=2.0 x[7]=2.0 x[0]=7.0 x[1]=7.0 x[2]=7.0 x[3]=7.0 x[4]=7.0 x[5]=7.0 x[6]=7.0 x[7]=7.0 x[0]=7.0 x[1]=7.0 x[2]=7.0 x[3]=7.0 x[4]=7.0 x[5]=7.0 x[6]=7.0 x[7]=7.0 x[0]=7.0 x[1]=7.0 x[2]=28.0 x[3]=21.0 x[4]=14.0 x[5]=7.0 x[6]=7.0 x[7]=7.0 x[0]=7.0 x[1]=7.0 x[2]=21.0 x[3]=14.0 x[4]=7.0 x[5]=7.0 x[6]=7.0 x[7]=7.0 x[0]=7.0 x[1]=7.0 x[2]=7.0 x[3]=21.0 x[4]=14.0 x[5]=7.0 x[6]=7.0 x[7]=7.0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.