C++ Program: NEED HELP! The following program prints the contents of the array b
ID: 3830354 • Letter: C
Question
C++ Program: NEED HELP!
The following program prints the contents of the array block_of_int row by row.
#include <iostream>
using namespace std;
int main()
{
int block_of_int[4][3]={{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
for (int row = 0; row < 4; row++)
{
for (int column = 0; column < 3; column++)
cout << block_of_int[row][column] << " ";
cout << " ";
}
return 0;
}
STEP 1: Modify the program so that it prints the array colum by column; that is, the modified program should print the first column of block_of_int, followed by the second column, followed y the third.
STEP 2: Modify the orginal program so that you can change the entires in the block_of_int from the keyboard.
1 2 3 4 5 6 89 10 11 12 Press any key to continueExplanation / Answer
#include <iostream>
using namespace std;
int main()
{
int block_of_int[4][3]={{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
for (int column = 0; column < 3; column++)
{
for (int row = 0; row < 4; row++)
cout << block_of_int[row][column] << " ";
cout << " ";
}
return 0;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
1 4 7 10
2 5 8 11
3 6 9 12
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.