Answer:
Following is the complete program
#include <iostream> // header file
using namespace std; // namespace
int main() // main method
{
int k=0;// variable declaartion
int nums[2][4] = {{17, 24, 86, 35},
{23, 36, 10, 12}}; // as mention in the question
cout << "column by column : \\";
while(k<4) //iterating the while loop{
for(int j1=0;j1<2;j1++) //iterating the for loop
{
cout << nums[j1][k] << " "; //display matrix
}
cout <<endl; // next line
k++; //increment the value of k
}
//display row by row
k=0;
cout << "row by row : \\";
while(k<2) //iterating the while loop
{
for(int j1=0;j1<4;j1++) //iterating the for loop
{
cout << nums[k][j1] << " "; //display matrix
}
cout << endl;
k++;
}
return 0;
} //end of main function
Output:
column by column :
17 23
24 36
86 10
35 12
row by row :
17 24 86 35
23 36 10 12
Step-by-step explanation:
In this question some information is missing .In this question the program is not given which we have to correct them .So following are the program which we have to correct it
Example program:
//Introductory22.cpp - displays the contents of a
//two-dimensional array, column by column and row by row
//Created/revised by <your name> on <current date>
#include <iostream> // header file
using namespace std; // namespace
int main() // main function
{
int nums[2][4] = {{17, 24, 86, 35},
{23, 36, 10, 12}};
//display column by column
cout << endl;
//display row by row
return 0;
} //end of main function
Following are the description of program :
- Declared a variable k and j1 as in the "int" type.The variable k is used for row and j1 is used for the indication of column .
- We have used while as an outer loop and for as inner loop .
- The statement cout << nums[j1][k] inside the inner loop will print the given matrix in the column format .
- The ststement cout << nums[k][j1] << " ";nside the inner loop will print the given matrix in the row format .