//Introductory20.cpp - displays the contents
//of a two-dimensional array, column by column
//and row by row
//Created/revised by <Miguel Mora> on <5/4/2014>
#include <iostream>
using namespace std;
int main()
{
int nums[2][4] = {{17, 24, 86, 35},
{23, 36, 10, 12}};
//display column by column
cout << endl;
//display row by row
system("pause");
return 0;
} //end of main function
I need help modifying a program that should display the contents of the two- dimensional array, column by column and also row by row. I need to complete the program using a WHILE statement in the outer loops and a FOR statement in the nested loops. Any help will be considered helpful, Thank you.
Let's think: if I have a bidimensional array and each one have 4 integers, when I access, it will return 4 integers. Then, I can access each one of these integers. So:
1 2 3
for each array in nums
for each number in array
show number
That become:
1 2 3 4 5
for(int i = 0; i < 2; i++)
{
for(int a = 0; a < 4; a++) std::cout << nums[i][a] << "\t"; // \t is tab; spacing
std::cout << std::endl; // skip line when print dimension
}