Unit #6 Homework Problem (Solution)
Course Outline HW & Programming Assignments
Sol6hw2c

Predict the output of the following program and also fill the table indicating the memory contents for j, k, and x at the end of the program

main ( )

{ float x [4][4];

int j, k ;

cout << setiosflags( ios:: scientific) << setprecision ( 3);

for ( j = 0; j <= 3; j = j + 1)

{ for ( k = 0; k <= 3 ; k++)

x [j][k] = k + 3.2 - k * ( j - 1.) ; }

for ( k = 1; k <= 3 ; k++)

cout << setw(20) << x[3][k] << endl;

cout << " enter e to exit";

char hold;

cin >> hold;

}

ANSWER: 

2.200e+00

1.200e+00

2.000e-01

--------------------------------- contents of j, k, and array X:

j = 4 k = 4

X array

3.20 5.20 7.20 9.20

3.20 4.20 5.20 6.20

3.20 3.20 3.20 3.20

3.20 2.20 1.20 0.20