Two-dimensional array declaration assignment traversing row-column swapping for maximum value, two-dimensional array assignment

Source: Internet
Author: User

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 ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.