Two-dimensional array declaration assignment traversing row-column swapping for maximum value, two-dimensional array assignment
Whether a two-dimensional array is an array element or an array
Declaration of two-dimensional arrays
Int arr [3] [4];
This two-dimensional array contains three one-dimensional arrays, each of which has four elements.
Assignment of two-dimensional arrays
Int arr [3] [4] = {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12 }};
Int arr [3] [4] = {1, 2, 3, 4 },
{5, 6, 7, 8 },
{9, 10, 11, 12 }};
Q:
What are the elements of the 1st rows and 1st columns of a two-dimensional array? 6
If the assignment is like this, what are the elements of the array?
Int arr [3] [4] = {1}, {0, 6}, {0, 11 }};
Int arr [3] [4] = },
{0, 6, 0, 0 },
{0, 0, 11, 0 }};
Traversal of two-dimensional arrays
// One-dimensional array sorting, selection method # include <iostream> using namespace std; int main () {// defines a one-dimensional array int arr [3] [4] = {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}; // traverse for (int I = 0; I <3; I ++) {for (int j = 0; j <4; j ++) {cout <arr [I] [j] <";}cout <endl ;} return 0 ;}
Use a two-dimensional array to swap array row and column elements
There is a two-dimensional array, which is two rows and three columns of int [2] [3].
Int [] a = {1, 2, 3 },
{4, 5, 6 }};
Convert the above array into an array of 3 rows and 2 columns int [3] [2]
Int [] B = {1, 4 },
{2, 5 },
{3, 6 }};
# Include <iostream> using namespace std; // how to use a one-dimensional array? Int main () {// an array is a container. This container features a storage space that cannot be changed. A fixed-size container // declares a one-dimensional array? An integer one-dimensional array means that all elements in the array are int array [2] [3] ={{, 3 },{, 6 }}; int arrayb [3] [2]; for (int I = 0; I <2; I ++) {for (int j = 0; j <3; j ++) {cout <"swap first second" <I <"row" <"second" <j <"column is" <array [I] [j ];} cout <endl ;}for (int I = 0; I <2; I ++) {for (int j = 0; j <3; j ++) {arrayb [j] [I] = array [I] [j] ;}// traversing a two-dimensional array for (int I = 0; I <3; I ++) {for (int j = 0; j <2; j ++) {cout <"Interchange after" <I <"row" <"after" <j <"column is" <arrayb [I] [j] ;} cout <endl;} return 0 ;}