Determine the output for each part below by hand (do not compile the programs).
ID: 652110 • Letter: D
Question
Determine the output for each part below by hand (do not compile the programs).
Part A
const int R = 4, C = 3;
double A[R][C]={1,2,3,4,5,6,7,8,9,10,11,12};
for (int i = 0; i < R; i++)
{ for (int j = 0; j < C; j++)
cout << setw(3) << A[i][j];
cout << endl; }
Part B
const int R = 4, C = 3;
double A[R][C]={1,2,3,4,5,6,7,8,9,10,11,12};
for (int i = 1; i < R; i++)
{ for (int j = 1; j < C; j++)
cout << setw(3) << A[i][j];
cout << endl; }
Part C
const int R = 4, C = 3;
double A[R][C]={1,2,3,4,5,6,7,8,9,10,11,12};
for (int j = 0; j < C; j++)
{ for (int i = 0; i < R; i++)
cout << setw(3) << A[i][j];
cout << endl; }
Part D
const int R = 4, C = 3;
double A[R][C]={1,2,3,4,5,6,7,8,9,10,11,12};
for (int i = R-1; i >= 0; i--)
{ for (int j = C-1; j >= 0; j--)
cout << setw(3) << A[i][j];
cout << endl; }
Part E
const int R = 4, C = 3;
double A[R][C]={1,2,3,4,5,6,7,8,9,10,11,12};
for (int i = 0; i < R; i++)
{ for (int j = 0; j < i+1; j++)
cout << setw(3) << A[i][j];
cout << endl; }
Part F
const int R = 4, C = 3;
double A[R][C]={1,2,3,4,5,6,7,8,9,10,11,12};
for (int i = 0; i < R; i++)
{ for (int j = 0; j < C; j++)
if(i>=j)cout<<setw(3)<<A[i][j];
cout << endl; }
Part A
const int R = 4, C = 3;
double A[R][C]={1,2,3,4,5,6,7,8,9,10,11,12};
for (int i = 0; i < R; i++)
{ for (int j = 0; j < C; j++)
cout << setw(3) << A[i][j];
cout << endl; }
Part B
const int R = 4, C = 3;
double A[R][C]={1,2,3,4,5,6,7,8,9,10,11,12};
for (int i = 1; i < R; i++)
{ for (int j = 1; j < C; j++)
cout << setw(3) << A[i][j];
cout << endl; }
Part C
const int R = 4, C = 3;
double A[R][C]={1,2,3,4,5,6,7,8,9,10,11,12};
for (int j = 0; j < C; j++)
{ for (int i = 0; i < R; i++)
cout << setw(3) << A[i][j];
cout << endl; }
Part D
const int R = 4, C = 3;
double A[R][C]={1,2,3,4,5,6,7,8,9,10,11,12};
for (int i = R-1; i >= 0; i--)
{ for (int j = C-1; j >= 0; j--)
cout << setw(3) << A[i][j];
cout << endl; }
Part E
const int R = 4, C = 3;
double A[R][C]={1,2,3,4,5,6,7,8,9,10,11,12};
for (int i = 0; i < R; i++)
{ for (int j = 0; j < i+1; j++)
cout << setw(3) << A[i][j];
cout << endl; }
Part F
const int R = 4, C = 3;
double A[R][C]={1,2,3,4,5,6,7,8,9,10,11,12};
for (int i = 0; i < R; i++)
{ for (int j = 0; j < C; j++)
if(i>=j)cout<<setw(3)<<A[i][j];
cout << endl; }
Explanation / Answer
partA
Whole array will be printed
1 2 3
4 5 6
7 8 9
10 11 12
partB
Whole array except the 1st column and the first row will be printed(because the loops are starting from 0)
5 6
8 9
11 12
partC
Whole array will be printed, but as a transpose of the output in partA(because inner and louter loops are interchanged)
1 4 7 10
2 5 8 11
3 6 9 12
partD
The array will pe printed in such a way that only the first 'k' elements of the 'k'th row are printed. Also, the last element in the last row will be garbage value because A[3][3] is not an element of an array
1
4 5
7 8 9
10 11 12<garbage value>
partE
The array will pe printed in such a way that only the first 'k' elements of the 'k'th row are printed. Also, the 4th row will have 3 elements because of the if condition
1
4 5
7 8 9
10 11 12
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.