Seven or two-d arrays

Source: Internet
Author: User
Tags array definition ticket

1. Only one subscript array is called a one-dimensional array, and there are two subscript arrays called two-dimensional arrays, and an array of n subscripts is called an n-dimensional array. 2. Two-D array definition:Type descriptorarray name [constant expression1[Constant expression2]={ Value 1, value 2, ... int A[2][3] = {{7,6,3},{2,8,5}}; Description 2 rows 3 columns array 3. Constant expression 1 indicates the length of the first-dimension subscriptconstant Expression 2 indicates the length of the second-dimension subscript4. Elements of a two-D array are also known as double subscript variables5. The assignment is typically used with a two-layer for loop nesting (double loop). The outer loop controls the number of rows, and the inner loop controls the number of columns corresponding to each row. 6. Purpose of the two-D array: Game map (1 means there is an obstacle, 0 means it can be passed here), cinema ticket (1 means the location has been sold, 0 means there is a ticket for this location). 7. Precautions:(1) when a two-dimensional array is defined, the length of the first dimension may not be specified, but the second dimension must be given. (2) The number of elements is insufficient, will be automatically filled8. Right-left principle, read first to the right and encounter parentheses reverse. //Two-dimensional array exchange
int a[2][3] = {0}, b[3][2] = {0};
for (int i = 0; i < 2; i + +) {//Control the output of two-dimensional array row numbers
for (int j = 0; J < 3; J + +) {//Control the output of two-dimensional array columns
A[I][J] = arc4random ()% (100-10 + 1) + 10;//Randomly generated arrays
printf ("%d", a[i][j]);//Output array
//            }
printf ("\ n");//Line break after one line of output is complete
//        }
printf ("After Exchange\ n ");
for (int i = 0; i < 2; i + +) {//Controls the number of rows that are exchanged for a two-dimensional array
for (int j = 0; J < 3; J + +) {//Controls the number of columns in a two-dimensional array that is swapped
B[j][i] = a[i][j];//Number of columns in the swapped array = number of rows, number of rows = number of columns
//            }
//        }
for (int i = 0; i < 3; i + +) {
for (int j = 0; J < 2; J + +) {
printf ("%d", b[i][j]);
//            }
printf ("\ n");
//        }
//Maximum value for two-dimensional array,Determines the position of the maximum value, if multiple, outputs multiple
int number[2][3] = {0};
int max = 0;
for (int i = 0; i < 2; i + +) {
for (int j = 0; J < 3; J + +) {
NUMBER[I][J] = arc4random ()% (100-10 + 1) + 10;
printf ("%d", number[i][j]);
//            }
printf ("\ n");
//        }
for (int i = 0; i < 2; i + +) {
for (int j = 0; J < 3; J + +) {
max = max > Number[i][j]? MAX:NUMBER[I][J];
//            }
//        }
printf ("max=%d\n", Max);
for (int i = 0; i < 2; i + +) {
for (int j = 0; J < 3; J + +) {
if (max = = Number[i][j]) {
printf ("i=%d j=%d", i,j);
break;// output only one Span style= "font:18.0px Menlo; Font-variant-ligatures:no-common-ligatures; " >
//                }
//            }
//         //printf ("\ n");9. An array, only subscript concept, give the group name and subscript can be manipulated.

Seven or two-d arrays

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.