logo

Cómo almacenar valor en una matriz

Una matriz es un grupo de elementos de tipo similar que tienen una ubicación de memoria contigua. Una matriz es una colección de variables del mismo tipo que se denominan mediante un nombre común.

Este tutorial descubrirá brevemente cómo almacenar valor en una matriz en los lenguajes de uso común.

hermanos kylie jenner

1. Lenguaje C

Todas las matrices son bloques contiguos de ubicaciones de memoria. De forma predeterminada, la posición más baja de la matriz almacena el primer elemento y la posición más alta almacena los últimos datos. En C, la matriz se declara especificando el tipo de elemento y la longitud total de la matriz requerida para almacenar los datos.

Sintaxis para declarar matriz

 type arrayName [ arrSize ]; 

Sintaxis para inicializar para almacenar valores de matriz

 double balance[6] = {500.0, 52.0, 63.6, 77.80, 70.10, 80.12}; 

Ejemplo

 #include int main () { int n[ 11 ]; /* declaring an array comprising of 11 integers */ int i,j; /* initialize elements of array n to 0 */ for ( i = 0; i <11; 100 i++ ) { n[ i ]="i" + 10; * storing or initializing the array at location with element } result of element's value for (j="0;" j < 11; j++ printf('element stored position [%d]="%d
&apos;," j, n[j] ); return 0; pre> <p> <strong>Output</strong> </p> <pre> Element stored at position [0] = 10 Element stored at position [1] = 11 Element stored at position [2] = 12 Element stored at position [3] = 13 Element stored at position [4] = 14 Element stored at position [5] = 15 Element stored at position [6] = 16 Element stored at position [7] = 17 Element stored at position [8] = 18 Element stored at position [9] = 19 Element stored at position [10] = 20 </pre> <h3>Multidimensional Array in C</h3> <p>In C language, the elements of a 2 D (two-dimensional) array are accessed with the help of subscripts, i.e., the row index number and the column index number of the array.</p> <p> <strong>Syntax for declaring Array</strong> </p> <pre> int val = arr[x][y]; </pre> <p> <strong>Syntax for Initializing Two-Dimensional Arrays</strong> </p> <pre> int a[1][4] = { {4, 4, 2, 1} , /* initializers for row indexed by 0 */ {4, 5, 16, 10} , /* initializers for row indexed by 1 */ {8, 19, 10, 11} /* initializers for row indexed by 2 */ }; </pre> <p> <strong></strong> </p> <pre> #include int main () { /* declaring and initializing the array with 4 rows and 2 columns*/ int arr[4][2] = { {1,0}, {1,2}, {2,4}, {3,6}}; int i, j; /* output each array element&apos;s value */ for ( i = 0; i <4; i++ ) { for ( j="0;" < 2; j++ printf(' data stored in 2d array[%d][%d]="%d
&apos;," i,j, arr[i][j] ); } return 0; pre> <p> <strong>Output</strong> </p> <pre> Data stored in 2D array[0][0] = 1 Data stored in 2D array[0][1] = 0 Data stored in 2D array[1][0] = 1 Data stored in 2D array[1][1] = 2 Data stored in 2D array[2][0] = 2 Data stored in 2D array[2][1] = 4 Data stored in 2D array[3][0] = 3 Data stored in 2D array[3][1] = 6 </pre> <h2>2. C++ Language</h2> <p>In C++ language the user needs to specify the element type and total length of array.</p> <p> <strong>Syntax to Declare Array</strong> </p> <pre> type arrName [ arrSize ]; </pre> <p> <strong>Syntax to initialize array</strong> </p> <pre> int arr[] = { 1, 2, 3, 4, 5 } </pre> <p> <strong>Example</strong> </p> <pre> #include using namespace std; int main () { // declaring an array with 4 rows. int arr[4] = {1,7,50,6}; // traversing the output for each array value for ( int i = 0; i <4; i++ ) { cout << 'array at position[' i ']: '; arr[i]<< endl; } return 0; < pre> <p> <strong>Output</strong> </p> <pre> array at position[0]: 1 array at position[1]: 7 array at position[2]: 50 array at position[3]: 6 </pre> <h3>Multidimensional Array</h3> <p>C++ language also enables the Multidimensional arrays.</p> <p> <strong>Syntax for initializing 2D array</strong> </p> <pre> int a[4][3] = { {0, 1, 2} , /* storing data in array for row indexed by 0 */ {42, 25, 62} , /* storing data in array for row indexed by 1 */ {18, 90, 15}, /* storing data in array for row indexed by 2 */ {21, 19, 25}, /* storing data in array for row indexed by 3 */ }; </pre> <p> <strong>Example</strong> </p> <pre> #include using namespace std; int main () { // declaring an array with 4 rows and 2 columns. int arr[4][2] = { {1,0}, {0,2}, {2,3}, {5,6}}; // traversing the output for each array value for ( int i = 0; i <4; i++ ) for ( int j="0;" < 2; j++ { cout << 'array at position[' i '][' ']: '; arr[i][j]<< endl; } return 0; pre> <p> <strong>Output</strong> </p> <pre> array at position[0][0]: 1 array at position[0][1]: 0 array at position[1][0]: 0 array at position[1][1]: 2 array at position[2][0]: 2 array at position[2][1]: 3 array at position[3][0]: 5 array at position[3][1]: 6 </pre> <h2>3. Java</h2> <p>In Java language, Arrays work differently than what they used to do in C or C++ language.</p> <h3>One-Dimensional Arrays:</h3> <p>To declare an array, the user needs to have two primary components: the type and the array&apos;s name.</p> <p>The &apos;Type&apos; refers to the elementary type of a specific array. It determines the data type of all elements that are included in the array. It comprises the array of primitive data types, unlike integers, char, float, double, etc., or it could include the user-defined data types (objects of a class) as well. Therefore, the element type for the array concludes what kind of data the array will contain.</p> <p> <strong>Syntax</strong> </p> <pre> type arr_var_name[]; OR type[] arr_var_name; OR var-name = new type [size]; </pre> <p> <strong>Store values in one-dimensional array</strong> </p> <p>Assigning values to an element in an array is similar to assigning values to scalar variables.</p> <pre> Array [index]= initializers; arr[1]= 50 arr[2]= 20 </pre> <h4>NOTE: It the array element is not assigned any value, by default it has a Null (empty) value.</h4> <p> <strong>Example</strong> </p> <pre> //Java Program to demonstrate how to initialize, store and display //values in one-dimensional arrays. class Testarray{ public static void main(String args[]){ int arr[]=new int[5];//declaration and instantiation arr[0]=20;//initialization of the array arr[1]=40; arr[2]=60; arr[3]=80; arr[4]=100; //traversing array to print the array values for(int i=0;i <arr.length;i++) system.out.println(arr[i]); }} < pre> <p> <strong>Output</strong> </p> <pre> 20 40 60 80 100 </pre> <h3>Arrays of Objects</h3> <p>An array of objects is constructed in the same way as an array of primitive type data elements.</p> <p> <strong>Example</strong> </p> <pre> // Java program to create, store and display values for one-dimensional // array of objects class Employee { public int id_no; public String name; Employee(int id_no, String name) { this.id_no = id_no; this.name = name; } } // The Elements of the array are objects of a class Employee. public class Array_Objects_Example { public static void main (String[] args) { // declares an Array of integers. Employee[] arr; // assigning space for 5 objects of type Employee. arr = new Employee[5]; // storing the value for the first element of the array arr[0] = new Employee(111,&apos;Varun&apos;); // storing the value for the second elements of the array arr[1] = new Employee(121,&apos;Sukla&apos;); // so on... arr[2] = new Employee(131,&apos;Virat&apos;); arr[3] = new Employee(141,&apos;Anuskha&apos;); arr[4] = new Employee(151,&apos;Mohit&apos;); // accessing the elements of the specified array for (int i = 0; i <arr.length; i++) system.out.println('element at ' + i : arr[i].id_no +' '+ arr[i].name); } < pre> <p> <strong>Output</strong> </p> <pre> Element at 0 : 111 Varun Element at 1 : 121 Sukla Element at 2 : 131 Virat Element at 3 : 141 Anuskha Element at 4 : 151 Mohit </pre> <h3>Multidimensional Arrays</h3> <p>Multidimensional arrays are termed &apos;arrays of arrays&apos; as they can hold each element of an array with the reference of another array. These are also known as Jagged Arrays. A multidimensional array is constructed by adding a set of square brackets ([]) per dimension.</p> <p> <strong>Syntax</strong> </p> <pre> int[][] intArray = new int[10][20]; //a 2D array or matrix int[][][] intArray = new int[10][20][10]; //a 3D array </pre> <p> <strong>Example to store values in a Multidimensional Array</strong> </p> <pre> arry[0][0]=10; arry[0][1]=20; arry[0][2]=30; arry[1][0]=40; arry[1][1]=50; arry[1][3]=60; arry[2][1]=70; arry[2][2]=80; arry[2][3]=90; </pre> <p> <strong>Example of Multidimensional Array</strong> </p> <pre> class multiDimensional_Example { public static void main(String args[]) { // declaring and storing data in 2-Dimensional array int arry[][] = { {12,17,19},{32,62,12},{37,34,32} }; // traversing and printing the 2-Dimensional array for (int i=0; i<3 3 ; i++) { for (int j="0;" < j++) system.out.print(arry[i][j] + ' '); system.out.println(); } pre> <p> <strong>Output</strong> </p> <pre> 12 17 19 32 62 12 37 34 32 </pre> <h2>4. PHP</h2> <p>PHP array is an ordered map (holds elements on the base of the key-value). It is utilized to hold multiple values of a similar data type in a single variable.</p> <p>PHP contains 3 kinds of array that are as follows:</p> <ol class="points"> <li>Indexed Array</li> <li>Associative Array</li> <li>Multidimensional Array</li> </ol> <h3>1. Indexed Array</h3> <p>PHP index is described by an integer number that begins with 0 (default value). The PHP array can store any data type, such as numbers, characters, strings, and objects. All PHP array data are allocated an index number by default.</p> <p> <strong>Syntax to store values</strong> </p> <pre> $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; </pre> <p> <strong>Example</strong> </p> <pre> </pre> <p> <strong>Output</strong> </p> <pre> Colours are: Red, White, Black, Yellow </pre> <h3>2. Associative Array</h3> <p>In PHP, the user can associate any specific name with each array elements using the &apos;=&gt;&apos; symbol.</p> <p> <strong>Syntax</strong> </p> <pre> $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; </pre> <p> <strong>Example</strong> </p> <pre> <?php $marks['Reema ']='95'; $marks['John']='45'; $marks ['Rahul ']='20'; echo 'Reema's Marks: '.$marks ['Reema '].' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 </pre> <h3>3. Multidimensional Array</h3> <p>Multidimensional arrays in PHP are also termed as &apos;array of arrays&apos;. It enabled the user to store array data in a tabular format. PHP multidimensional array can be expressed in the form of a matrix which is denoted by row * column.</p> <p> <strong>Syntax</strong> </p> <pre> $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); </pre> <p> <strong>Example</strong> </p> <pre> <?php $emp = array ( array (1,'Reema',95), array(2,'john',45), array(3,'rahul',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].' '; } echo ' <br/>&apos;; } ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> 1 Reema 95 2 john 45 3 rahul 20 </pre> <h2>5. Python</h2> <p>Python uses a module named &apos;Array&apos; to handle all the functions of Arrays in Python. It is helpful when the user wants to manipulate only particular data values. Given below are the keywords that are important to learn the concept of an array in Python:</p> <ul> <li>Element - Any data stored in an array is known an element.</li> <li>Index - Whenever an array stores any data, it has some numerical location known as index that is beneficial to identify the location of the element.</li> </ul> <p> <strong>Syntax</strong> </p> <pre> from array import * arrayName = array(typecode, [data_to_be_initialized]) </pre> <p> <strong>Example</strong> </p> <pre> import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) </pre> <p> <strong>Output</strong> </p> <pre> First array value: 20 Second array value: 40 Second last array value: 80 </pre> <hr></3></pre></arr.length;></pre></arr.length;i++)></pre></4;></pre></4;></pre></4;></pre></11;>

Matriz multidimensional en C

En lenguaje C, se accede a los elementos de una matriz 2 D (bidimensional) con la ayuda de subíndices, es decir, el número de índice de fila y el número de índice de columna de la matriz.

Sintaxis para declarar Array

 int val = arr[x][y]; 

Sintaxis para inicializar matrices bidimensionales

 int a[1][4] = { {4, 4, 2, 1} , /* initializers for row indexed by 0 */ {4, 5, 16, 10} , /* initializers for row indexed by 1 */ {8, 19, 10, 11} /* initializers for row indexed by 2 */ }; 

 #include int main () { /* declaring and initializing the array with 4 rows and 2 columns*/ int arr[4][2] = { {1,0}, {1,2}, {2,4}, {3,6}}; int i, j; /* output each array element&apos;s value */ for ( i = 0; i <4; i++ ) { for ( j="0;" < 2; j++ printf(\' data stored in 2d array[%d][%d]="%d
&apos;," i,j, arr[i][j] ); } return 0; pre> <p> <strong>Output</strong> </p> <pre> Data stored in 2D array[0][0] = 1 Data stored in 2D array[0][1] = 0 Data stored in 2D array[1][0] = 1 Data stored in 2D array[1][1] = 2 Data stored in 2D array[2][0] = 2 Data stored in 2D array[2][1] = 4 Data stored in 2D array[3][0] = 3 Data stored in 2D array[3][1] = 6 </pre> <h2>2. C++ Language</h2> <p>In C++ language the user needs to specify the element type and total length of array.</p> <p> <strong>Syntax to Declare Array</strong> </p> <pre> type arrName [ arrSize ]; </pre> <p> <strong>Syntax to initialize array</strong> </p> <pre> int arr[] = { 1, 2, 3, 4, 5 } </pre> <p> <strong>Example</strong> </p> <pre> #include using namespace std; int main () { // declaring an array with 4 rows. int arr[4] = {1,7,50,6}; // traversing the output for each array value for ( int i = 0; i <4; i++ ) { cout << \'array at position[\' i \']: \'; arr[i]<< endl; } return 0; < pre> <p> <strong>Output</strong> </p> <pre> array at position[0]: 1 array at position[1]: 7 array at position[2]: 50 array at position[3]: 6 </pre> <h3>Multidimensional Array</h3> <p>C++ language also enables the Multidimensional arrays.</p> <p> <strong>Syntax for initializing 2D array</strong> </p> <pre> int a[4][3] = { {0, 1, 2} , /* storing data in array for row indexed by 0 */ {42, 25, 62} , /* storing data in array for row indexed by 1 */ {18, 90, 15}, /* storing data in array for row indexed by 2 */ {21, 19, 25}, /* storing data in array for row indexed by 3 */ }; </pre> <p> <strong>Example</strong> </p> <pre> #include using namespace std; int main () { // declaring an array with 4 rows and 2 columns. int arr[4][2] = { {1,0}, {0,2}, {2,3}, {5,6}}; // traversing the output for each array value for ( int i = 0; i <4; i++ ) for ( int j="0;" < 2; j++ { cout << \'array at position[\' i \'][\' \']: \'; arr[i][j]<< endl; } return 0; pre> <p> <strong>Output</strong> </p> <pre> array at position[0][0]: 1 array at position[0][1]: 0 array at position[1][0]: 0 array at position[1][1]: 2 array at position[2][0]: 2 array at position[2][1]: 3 array at position[3][0]: 5 array at position[3][1]: 6 </pre> <h2>3. Java</h2> <p>In Java language, Arrays work differently than what they used to do in C or C++ language.</p> <h3>One-Dimensional Arrays:</h3> <p>To declare an array, the user needs to have two primary components: the type and the array&apos;s name.</p> <p>The &apos;Type&apos; refers to the elementary type of a specific array. It determines the data type of all elements that are included in the array. It comprises the array of primitive data types, unlike integers, char, float, double, etc., or it could include the user-defined data types (objects of a class) as well. Therefore, the element type for the array concludes what kind of data the array will contain.</p> <p> <strong>Syntax</strong> </p> <pre> type arr_var_name[]; OR type[] arr_var_name; OR var-name = new type [size]; </pre> <p> <strong>Store values in one-dimensional array</strong> </p> <p>Assigning values to an element in an array is similar to assigning values to scalar variables.</p> <pre> Array [index]= initializers; arr[1]= 50 arr[2]= 20 </pre> <h4>NOTE: It the array element is not assigned any value, by default it has a Null (empty) value.</h4> <p> <strong>Example</strong> </p> <pre> //Java Program to demonstrate how to initialize, store and display //values in one-dimensional arrays. class Testarray{ public static void main(String args[]){ int arr[]=new int[5];//declaration and instantiation arr[0]=20;//initialization of the array arr[1]=40; arr[2]=60; arr[3]=80; arr[4]=100; //traversing array to print the array values for(int i=0;i <arr.length;i++) system.out.println(arr[i]); }} < pre> <p> <strong>Output</strong> </p> <pre> 20 40 60 80 100 </pre> <h3>Arrays of Objects</h3> <p>An array of objects is constructed in the same way as an array of primitive type data elements.</p> <p> <strong>Example</strong> </p> <pre> // Java program to create, store and display values for one-dimensional // array of objects class Employee { public int id_no; public String name; Employee(int id_no, String name) { this.id_no = id_no; this.name = name; } } // The Elements of the array are objects of a class Employee. public class Array_Objects_Example { public static void main (String[] args) { // declares an Array of integers. Employee[] arr; // assigning space for 5 objects of type Employee. arr = new Employee[5]; // storing the value for the first element of the array arr[0] = new Employee(111,&apos;Varun&apos;); // storing the value for the second elements of the array arr[1] = new Employee(121,&apos;Sukla&apos;); // so on... arr[2] = new Employee(131,&apos;Virat&apos;); arr[3] = new Employee(141,&apos;Anuskha&apos;); arr[4] = new Employee(151,&apos;Mohit&apos;); // accessing the elements of the specified array for (int i = 0; i <arr.length; i++) system.out.println(\'element at \' + i : arr[i].id_no +\' \'+ arr[i].name); } < pre> <p> <strong>Output</strong> </p> <pre> Element at 0 : 111 Varun Element at 1 : 121 Sukla Element at 2 : 131 Virat Element at 3 : 141 Anuskha Element at 4 : 151 Mohit </pre> <h3>Multidimensional Arrays</h3> <p>Multidimensional arrays are termed &apos;arrays of arrays&apos; as they can hold each element of an array with the reference of another array. These are also known as Jagged Arrays. A multidimensional array is constructed by adding a set of square brackets ([]) per dimension.</p> <p> <strong>Syntax</strong> </p> <pre> int[][] intArray = new int[10][20]; //a 2D array or matrix int[][][] intArray = new int[10][20][10]; //a 3D array </pre> <p> <strong>Example to store values in a Multidimensional Array</strong> </p> <pre> arry[0][0]=10; arry[0][1]=20; arry[0][2]=30; arry[1][0]=40; arry[1][1]=50; arry[1][3]=60; arry[2][1]=70; arry[2][2]=80; arry[2][3]=90; </pre> <p> <strong>Example of Multidimensional Array</strong> </p> <pre> class multiDimensional_Example { public static void main(String args[]) { // declaring and storing data in 2-Dimensional array int arry[][] = { {12,17,19},{32,62,12},{37,34,32} }; // traversing and printing the 2-Dimensional array for (int i=0; i<3 3 ; i++) { for (int j="0;" < j++) system.out.print(arry[i][j] + \' \'); system.out.println(); } pre> <p> <strong>Output</strong> </p> <pre> 12 17 19 32 62 12 37 34 32 </pre> <h2>4. PHP</h2> <p>PHP array is an ordered map (holds elements on the base of the key-value). It is utilized to hold multiple values of a similar data type in a single variable.</p> <p>PHP contains 3 kinds of array that are as follows:</p> <ol class="points"> <li>Indexed Array</li> <li>Associative Array</li> <li>Multidimensional Array</li> </ol> <h3>1. Indexed Array</h3> <p>PHP index is described by an integer number that begins with 0 (default value). The PHP array can store any data type, such as numbers, characters, strings, and objects. All PHP array data are allocated an index number by default.</p> <p> <strong>Syntax to store values</strong> </p> <pre> $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; </pre> <p> <strong>Example</strong> </p> <pre> </pre> <p> <strong>Output</strong> </p> <pre> Colours are: Red, White, Black, Yellow </pre> <h3>2. Associative Array</h3> <p>In PHP, the user can associate any specific name with each array elements using the &apos;=&gt;&apos; symbol.</p> <p> <strong>Syntax</strong> </p> <pre> $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; </pre> <p> <strong>Example</strong> </p> <pre> <?php $marks[\'Reema \']=\'95\'; $marks[\'John\']=\'45\'; $marks [\'Rahul \']=\'20\'; echo \'Reema\'s Marks: \'.$marks [\'Reema \'].\' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 </pre> <h3>3. Multidimensional Array</h3> <p>Multidimensional arrays in PHP are also termed as &apos;array of arrays&apos;. It enabled the user to store array data in a tabular format. PHP multidimensional array can be expressed in the form of a matrix which is denoted by row * column.</p> <p> <strong>Syntax</strong> </p> <pre> $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); </pre> <p> <strong>Example</strong> </p> <pre> <?php $emp = array ( array (1,\'Reema\',95), array(2,\'john\',45), array(3,\'rahul\',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].\' \'; } echo \' <br/>&apos;; } ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> 1 Reema 95 2 john 45 3 rahul 20 </pre> <h2>5. Python</h2> <p>Python uses a module named &apos;Array&apos; to handle all the functions of Arrays in Python. It is helpful when the user wants to manipulate only particular data values. Given below are the keywords that are important to learn the concept of an array in Python:</p> <ul> <li>Element - Any data stored in an array is known an element.</li> <li>Index - Whenever an array stores any data, it has some numerical location known as index that is beneficial to identify the location of the element.</li> </ul> <p> <strong>Syntax</strong> </p> <pre> from array import * arrayName = array(typecode, [data_to_be_initialized]) </pre> <p> <strong>Example</strong> </p> <pre> import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) </pre> <p> <strong>Output</strong> </p> <pre> First array value: 20 Second array value: 40 Second last array value: 80 </pre> <hr></3></pre></arr.length;></pre></arr.length;i++)></pre></4;></pre></4;></pre></4;>

2. Lenguaje C++

En lenguaje C++, el usuario debe especificar el tipo de elemento y la longitud total de la matriz.

Sintaxis para declarar matriz

 type arrName [ arrSize ]; 

Sintaxis para inicializar la matriz

 int arr[] = { 1, 2, 3, 4, 5 } 

Ejemplo

 #include using namespace std; int main () { // declaring an array with 4 rows. int arr[4] = {1,7,50,6}; // traversing the output for each array value for ( int i = 0; i <4; i++ ) { cout << \'array at position[\' i \']: \'; arr[i]<< endl; } return 0; < pre> <p> <strong>Output</strong> </p> <pre> array at position[0]: 1 array at position[1]: 7 array at position[2]: 50 array at position[3]: 6 </pre> <h3>Multidimensional Array</h3> <p>C++ language also enables the Multidimensional arrays.</p> <p> <strong>Syntax for initializing 2D array</strong> </p> <pre> int a[4][3] = { {0, 1, 2} , /* storing data in array for row indexed by 0 */ {42, 25, 62} , /* storing data in array for row indexed by 1 */ {18, 90, 15}, /* storing data in array for row indexed by 2 */ {21, 19, 25}, /* storing data in array for row indexed by 3 */ }; </pre> <p> <strong>Example</strong> </p> <pre> #include using namespace std; int main () { // declaring an array with 4 rows and 2 columns. int arr[4][2] = { {1,0}, {0,2}, {2,3}, {5,6}}; // traversing the output for each array value for ( int i = 0; i <4; i++ ) for ( int j="0;" < 2; j++ { cout << \'array at position[\' i \'][\' \']: \'; arr[i][j]<< endl; } return 0; pre> <p> <strong>Output</strong> </p> <pre> array at position[0][0]: 1 array at position[0][1]: 0 array at position[1][0]: 0 array at position[1][1]: 2 array at position[2][0]: 2 array at position[2][1]: 3 array at position[3][0]: 5 array at position[3][1]: 6 </pre> <h2>3. Java</h2> <p>In Java language, Arrays work differently than what they used to do in C or C++ language.</p> <h3>One-Dimensional Arrays:</h3> <p>To declare an array, the user needs to have two primary components: the type and the array&apos;s name.</p> <p>The &apos;Type&apos; refers to the elementary type of a specific array. It determines the data type of all elements that are included in the array. It comprises the array of primitive data types, unlike integers, char, float, double, etc., or it could include the user-defined data types (objects of a class) as well. Therefore, the element type for the array concludes what kind of data the array will contain.</p> <p> <strong>Syntax</strong> </p> <pre> type arr_var_name[]; OR type[] arr_var_name; OR var-name = new type [size]; </pre> <p> <strong>Store values in one-dimensional array</strong> </p> <p>Assigning values to an element in an array is similar to assigning values to scalar variables.</p> <pre> Array [index]= initializers; arr[1]= 50 arr[2]= 20 </pre> <h4>NOTE: It the array element is not assigned any value, by default it has a Null (empty) value.</h4> <p> <strong>Example</strong> </p> <pre> //Java Program to demonstrate how to initialize, store and display //values in one-dimensional arrays. class Testarray{ public static void main(String args[]){ int arr[]=new int[5];//declaration and instantiation arr[0]=20;//initialization of the array arr[1]=40; arr[2]=60; arr[3]=80; arr[4]=100; //traversing array to print the array values for(int i=0;i <arr.length;i++) system.out.println(arr[i]); }} < pre> <p> <strong>Output</strong> </p> <pre> 20 40 60 80 100 </pre> <h3>Arrays of Objects</h3> <p>An array of objects is constructed in the same way as an array of primitive type data elements.</p> <p> <strong>Example</strong> </p> <pre> // Java program to create, store and display values for one-dimensional // array of objects class Employee { public int id_no; public String name; Employee(int id_no, String name) { this.id_no = id_no; this.name = name; } } // The Elements of the array are objects of a class Employee. public class Array_Objects_Example { public static void main (String[] args) { // declares an Array of integers. Employee[] arr; // assigning space for 5 objects of type Employee. arr = new Employee[5]; // storing the value for the first element of the array arr[0] = new Employee(111,&apos;Varun&apos;); // storing the value for the second elements of the array arr[1] = new Employee(121,&apos;Sukla&apos;); // so on... arr[2] = new Employee(131,&apos;Virat&apos;); arr[3] = new Employee(141,&apos;Anuskha&apos;); arr[4] = new Employee(151,&apos;Mohit&apos;); // accessing the elements of the specified array for (int i = 0; i <arr.length; i++) system.out.println(\'element at \' + i : arr[i].id_no +\' \'+ arr[i].name); } < pre> <p> <strong>Output</strong> </p> <pre> Element at 0 : 111 Varun Element at 1 : 121 Sukla Element at 2 : 131 Virat Element at 3 : 141 Anuskha Element at 4 : 151 Mohit </pre> <h3>Multidimensional Arrays</h3> <p>Multidimensional arrays are termed &apos;arrays of arrays&apos; as they can hold each element of an array with the reference of another array. These are also known as Jagged Arrays. A multidimensional array is constructed by adding a set of square brackets ([]) per dimension.</p> <p> <strong>Syntax</strong> </p> <pre> int[][] intArray = new int[10][20]; //a 2D array or matrix int[][][] intArray = new int[10][20][10]; //a 3D array </pre> <p> <strong>Example to store values in a Multidimensional Array</strong> </p> <pre> arry[0][0]=10; arry[0][1]=20; arry[0][2]=30; arry[1][0]=40; arry[1][1]=50; arry[1][3]=60; arry[2][1]=70; arry[2][2]=80; arry[2][3]=90; </pre> <p> <strong>Example of Multidimensional Array</strong> </p> <pre> class multiDimensional_Example { public static void main(String args[]) { // declaring and storing data in 2-Dimensional array int arry[][] = { {12,17,19},{32,62,12},{37,34,32} }; // traversing and printing the 2-Dimensional array for (int i=0; i<3 3 ; i++) { for (int j="0;" < j++) system.out.print(arry[i][j] + \' \'); system.out.println(); } pre> <p> <strong>Output</strong> </p> <pre> 12 17 19 32 62 12 37 34 32 </pre> <h2>4. PHP</h2> <p>PHP array is an ordered map (holds elements on the base of the key-value). It is utilized to hold multiple values of a similar data type in a single variable.</p> <p>PHP contains 3 kinds of array that are as follows:</p> <ol class="points"> <li>Indexed Array</li> <li>Associative Array</li> <li>Multidimensional Array</li> </ol> <h3>1. Indexed Array</h3> <p>PHP index is described by an integer number that begins with 0 (default value). The PHP array can store any data type, such as numbers, characters, strings, and objects. All PHP array data are allocated an index number by default.</p> <p> <strong>Syntax to store values</strong> </p> <pre> $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; </pre> <p> <strong>Example</strong> </p> <pre> </pre> <p> <strong>Output</strong> </p> <pre> Colours are: Red, White, Black, Yellow </pre> <h3>2. Associative Array</h3> <p>In PHP, the user can associate any specific name with each array elements using the &apos;=&gt;&apos; symbol.</p> <p> <strong>Syntax</strong> </p> <pre> $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; </pre> <p> <strong>Example</strong> </p> <pre> <?php $marks[\'Reema \']=\'95\'; $marks[\'John\']=\'45\'; $marks [\'Rahul \']=\'20\'; echo \'Reema\'s Marks: \'.$marks [\'Reema \'].\' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 </pre> <h3>3. Multidimensional Array</h3> <p>Multidimensional arrays in PHP are also termed as &apos;array of arrays&apos;. It enabled the user to store array data in a tabular format. PHP multidimensional array can be expressed in the form of a matrix which is denoted by row * column.</p> <p> <strong>Syntax</strong> </p> <pre> $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); </pre> <p> <strong>Example</strong> </p> <pre> <?php $emp = array ( array (1,\'Reema\',95), array(2,\'john\',45), array(3,\'rahul\',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].\' \'; } echo \' <br/>&apos;; } ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> 1 Reema 95 2 john 45 3 rahul 20 </pre> <h2>5. Python</h2> <p>Python uses a module named &apos;Array&apos; to handle all the functions of Arrays in Python. It is helpful when the user wants to manipulate only particular data values. Given below are the keywords that are important to learn the concept of an array in Python:</p> <ul> <li>Element - Any data stored in an array is known an element.</li> <li>Index - Whenever an array stores any data, it has some numerical location known as index that is beneficial to identify the location of the element.</li> </ul> <p> <strong>Syntax</strong> </p> <pre> from array import * arrayName = array(typecode, [data_to_be_initialized]) </pre> <p> <strong>Example</strong> </p> <pre> import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) </pre> <p> <strong>Output</strong> </p> <pre> First array value: 20 Second array value: 40 Second last array value: 80 </pre> <hr></3></pre></arr.length;></pre></arr.length;i++)></pre></4;></pre></4;>

Matriz multidimensional

El lenguaje C++ también permite las matrices multidimensionales.

Sintaxis para inicializar una matriz 2D

 int a[4][3] = { {0, 1, 2} , /* storing data in array for row indexed by 0 */ {42, 25, 62} , /* storing data in array for row indexed by 1 */ {18, 90, 15}, /* storing data in array for row indexed by 2 */ {21, 19, 25}, /* storing data in array for row indexed by 3 */ }; 

Ejemplo

 #include using namespace std; int main () { // declaring an array with 4 rows and 2 columns. int arr[4][2] = { {1,0}, {0,2}, {2,3}, {5,6}}; // traversing the output for each array value for ( int i = 0; i <4; i++ ) for ( int j="0;" < 2; j++ { cout << \'array at position[\' i \'][\' \']: \'; arr[i][j]<< endl; } return 0; pre> <p> <strong>Output</strong> </p> <pre> array at position[0][0]: 1 array at position[0][1]: 0 array at position[1][0]: 0 array at position[1][1]: 2 array at position[2][0]: 2 array at position[2][1]: 3 array at position[3][0]: 5 array at position[3][1]: 6 </pre> <h2>3. Java</h2> <p>In Java language, Arrays work differently than what they used to do in C or C++ language.</p> <h3>One-Dimensional Arrays:</h3> <p>To declare an array, the user needs to have two primary components: the type and the array&apos;s name.</p> <p>The &apos;Type&apos; refers to the elementary type of a specific array. It determines the data type of all elements that are included in the array. It comprises the array of primitive data types, unlike integers, char, float, double, etc., or it could include the user-defined data types (objects of a class) as well. Therefore, the element type for the array concludes what kind of data the array will contain.</p> <p> <strong>Syntax</strong> </p> <pre> type arr_var_name[]; OR type[] arr_var_name; OR var-name = new type [size]; </pre> <p> <strong>Store values in one-dimensional array</strong> </p> <p>Assigning values to an element in an array is similar to assigning values to scalar variables.</p> <pre> Array [index]= initializers; arr[1]= 50 arr[2]= 20 </pre> <h4>NOTE: It the array element is not assigned any value, by default it has a Null (empty) value.</h4> <p> <strong>Example</strong> </p> <pre> //Java Program to demonstrate how to initialize, store and display //values in one-dimensional arrays. class Testarray{ public static void main(String args[]){ int arr[]=new int[5];//declaration and instantiation arr[0]=20;//initialization of the array arr[1]=40; arr[2]=60; arr[3]=80; arr[4]=100; //traversing array to print the array values for(int i=0;i <arr.length;i++) system.out.println(arr[i]); }} < pre> <p> <strong>Output</strong> </p> <pre> 20 40 60 80 100 </pre> <h3>Arrays of Objects</h3> <p>An array of objects is constructed in the same way as an array of primitive type data elements.</p> <p> <strong>Example</strong> </p> <pre> // Java program to create, store and display values for one-dimensional // array of objects class Employee { public int id_no; public String name; Employee(int id_no, String name) { this.id_no = id_no; this.name = name; } } // The Elements of the array are objects of a class Employee. public class Array_Objects_Example { public static void main (String[] args) { // declares an Array of integers. Employee[] arr; // assigning space for 5 objects of type Employee. arr = new Employee[5]; // storing the value for the first element of the array arr[0] = new Employee(111,&apos;Varun&apos;); // storing the value for the second elements of the array arr[1] = new Employee(121,&apos;Sukla&apos;); // so on... arr[2] = new Employee(131,&apos;Virat&apos;); arr[3] = new Employee(141,&apos;Anuskha&apos;); arr[4] = new Employee(151,&apos;Mohit&apos;); // accessing the elements of the specified array for (int i = 0; i <arr.length; i++) system.out.println(\'element at \' + i : arr[i].id_no +\' \'+ arr[i].name); } < pre> <p> <strong>Output</strong> </p> <pre> Element at 0 : 111 Varun Element at 1 : 121 Sukla Element at 2 : 131 Virat Element at 3 : 141 Anuskha Element at 4 : 151 Mohit </pre> <h3>Multidimensional Arrays</h3> <p>Multidimensional arrays are termed &apos;arrays of arrays&apos; as they can hold each element of an array with the reference of another array. These are also known as Jagged Arrays. A multidimensional array is constructed by adding a set of square brackets ([]) per dimension.</p> <p> <strong>Syntax</strong> </p> <pre> int[][] intArray = new int[10][20]; //a 2D array or matrix int[][][] intArray = new int[10][20][10]; //a 3D array </pre> <p> <strong>Example to store values in a Multidimensional Array</strong> </p> <pre> arry[0][0]=10; arry[0][1]=20; arry[0][2]=30; arry[1][0]=40; arry[1][1]=50; arry[1][3]=60; arry[2][1]=70; arry[2][2]=80; arry[2][3]=90; </pre> <p> <strong>Example of Multidimensional Array</strong> </p> <pre> class multiDimensional_Example { public static void main(String args[]) { // declaring and storing data in 2-Dimensional array int arry[][] = { {12,17,19},{32,62,12},{37,34,32} }; // traversing and printing the 2-Dimensional array for (int i=0; i<3 3 ; i++) { for (int j="0;" < j++) system.out.print(arry[i][j] + \' \'); system.out.println(); } pre> <p> <strong>Output</strong> </p> <pre> 12 17 19 32 62 12 37 34 32 </pre> <h2>4. PHP</h2> <p>PHP array is an ordered map (holds elements on the base of the key-value). It is utilized to hold multiple values of a similar data type in a single variable.</p> <p>PHP contains 3 kinds of array that are as follows:</p> <ol class="points"> <li>Indexed Array</li> <li>Associative Array</li> <li>Multidimensional Array</li> </ol> <h3>1. Indexed Array</h3> <p>PHP index is described by an integer number that begins with 0 (default value). The PHP array can store any data type, such as numbers, characters, strings, and objects. All PHP array data are allocated an index number by default.</p> <p> <strong>Syntax to store values</strong> </p> <pre> $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; </pre> <p> <strong>Example</strong> </p> <pre> </pre> <p> <strong>Output</strong> </p> <pre> Colours are: Red, White, Black, Yellow </pre> <h3>2. Associative Array</h3> <p>In PHP, the user can associate any specific name with each array elements using the &apos;=&gt;&apos; symbol.</p> <p> <strong>Syntax</strong> </p> <pre> $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; </pre> <p> <strong>Example</strong> </p> <pre> <?php $marks[\'Reema \']=\'95\'; $marks[\'John\']=\'45\'; $marks [\'Rahul \']=\'20\'; echo \'Reema\'s Marks: \'.$marks [\'Reema \'].\' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 </pre> <h3>3. Multidimensional Array</h3> <p>Multidimensional arrays in PHP are also termed as &apos;array of arrays&apos;. It enabled the user to store array data in a tabular format. PHP multidimensional array can be expressed in the form of a matrix which is denoted by row * column.</p> <p> <strong>Syntax</strong> </p> <pre> $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); </pre> <p> <strong>Example</strong> </p> <pre> <?php $emp = array ( array (1,\'Reema\',95), array(2,\'john\',45), array(3,\'rahul\',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].\' \'; } echo \' <br/>&apos;; } ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> 1 Reema 95 2 john 45 3 rahul 20 </pre> <h2>5. Python</h2> <p>Python uses a module named &apos;Array&apos; to handle all the functions of Arrays in Python. It is helpful when the user wants to manipulate only particular data values. Given below are the keywords that are important to learn the concept of an array in Python:</p> <ul> <li>Element - Any data stored in an array is known an element.</li> <li>Index - Whenever an array stores any data, it has some numerical location known as index that is beneficial to identify the location of the element.</li> </ul> <p> <strong>Syntax</strong> </p> <pre> from array import * arrayName = array(typecode, [data_to_be_initialized]) </pre> <p> <strong>Example</strong> </p> <pre> import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) </pre> <p> <strong>Output</strong> </p> <pre> First array value: 20 Second array value: 40 Second last array value: 80 </pre> <hr></3></pre></arr.length;></pre></arr.length;i++)></pre></4;>

3.Java

En el lenguaje Java, los Arrays funcionan de manera diferente a como solían hacerlo en el lenguaje C o C++.

Matrices unidimensionales:

Para declarar una matriz, el usuario necesita tener dos componentes principales: el tipo y el nombre de la matriz.

El 'Tipo' se refiere al tipo elemental de una matriz específica. Determina el tipo de datos de todos los elementos que se incluyen en la matriz. Comprende una matriz de tipos de datos primitivos, a diferencia de los enteros, char, float, double, etc., o también podría incluir los tipos de datos definidos por el usuario (objetos de una clase). Por lo tanto, el tipo de elemento de la matriz concluye qué tipo de datos contendrá la matriz.

Sintaxis

 type arr_var_name[]; OR type[] arr_var_name; OR var-name = new type [size]; 

Almacenar valores en una matriz unidimensional

Asignar valores a un elemento de una matriz es similar a asignar valores a variables escalares.

 Array [index]= initializers; arr[1]= 50 arr[2]= 20 

NOTA: Si al elemento de la matriz no se le asigna ningún valor, de forma predeterminada tiene un valor Nulo (vacío).

Ejemplo

nombre de usuario
 //Java Program to demonstrate how to initialize, store and display //values in one-dimensional arrays. class Testarray{ public static void main(String args[]){ int arr[]=new int[5];//declaration and instantiation arr[0]=20;//initialization of the array arr[1]=40; arr[2]=60; arr[3]=80; arr[4]=100; //traversing array to print the array values for(int i=0;i <arr.length;i++) system.out.println(arr[i]); }} < pre> <p> <strong>Output</strong> </p> <pre> 20 40 60 80 100 </pre> <h3>Arrays of Objects</h3> <p>An array of objects is constructed in the same way as an array of primitive type data elements.</p> <p> <strong>Example</strong> </p> <pre> // Java program to create, store and display values for one-dimensional // array of objects class Employee { public int id_no; public String name; Employee(int id_no, String name) { this.id_no = id_no; this.name = name; } } // The Elements of the array are objects of a class Employee. public class Array_Objects_Example { public static void main (String[] args) { // declares an Array of integers. Employee[] arr; // assigning space for 5 objects of type Employee. arr = new Employee[5]; // storing the value for the first element of the array arr[0] = new Employee(111,&apos;Varun&apos;); // storing the value for the second elements of the array arr[1] = new Employee(121,&apos;Sukla&apos;); // so on... arr[2] = new Employee(131,&apos;Virat&apos;); arr[3] = new Employee(141,&apos;Anuskha&apos;); arr[4] = new Employee(151,&apos;Mohit&apos;); // accessing the elements of the specified array for (int i = 0; i <arr.length; i++) system.out.println(\'element at \' + i : arr[i].id_no +\' \'+ arr[i].name); } < pre> <p> <strong>Output</strong> </p> <pre> Element at 0 : 111 Varun Element at 1 : 121 Sukla Element at 2 : 131 Virat Element at 3 : 141 Anuskha Element at 4 : 151 Mohit </pre> <h3>Multidimensional Arrays</h3> <p>Multidimensional arrays are termed &apos;arrays of arrays&apos; as they can hold each element of an array with the reference of another array. These are also known as Jagged Arrays. A multidimensional array is constructed by adding a set of square brackets ([]) per dimension.</p> <p> <strong>Syntax</strong> </p> <pre> int[][] intArray = new int[10][20]; //a 2D array or matrix int[][][] intArray = new int[10][20][10]; //a 3D array </pre> <p> <strong>Example to store values in a Multidimensional Array</strong> </p> <pre> arry[0][0]=10; arry[0][1]=20; arry[0][2]=30; arry[1][0]=40; arry[1][1]=50; arry[1][3]=60; arry[2][1]=70; arry[2][2]=80; arry[2][3]=90; </pre> <p> <strong>Example of Multidimensional Array</strong> </p> <pre> class multiDimensional_Example { public static void main(String args[]) { // declaring and storing data in 2-Dimensional array int arry[][] = { {12,17,19},{32,62,12},{37,34,32} }; // traversing and printing the 2-Dimensional array for (int i=0; i<3 3 ; i++) { for (int j="0;" < j++) system.out.print(arry[i][j] + \' \'); system.out.println(); } pre> <p> <strong>Output</strong> </p> <pre> 12 17 19 32 62 12 37 34 32 </pre> <h2>4. PHP</h2> <p>PHP array is an ordered map (holds elements on the base of the key-value). It is utilized to hold multiple values of a similar data type in a single variable.</p> <p>PHP contains 3 kinds of array that are as follows:</p> <ol class="points"> <li>Indexed Array</li> <li>Associative Array</li> <li>Multidimensional Array</li> </ol> <h3>1. Indexed Array</h3> <p>PHP index is described by an integer number that begins with 0 (default value). The PHP array can store any data type, such as numbers, characters, strings, and objects. All PHP array data are allocated an index number by default.</p> <p> <strong>Syntax to store values</strong> </p> <pre> $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; </pre> <p> <strong>Example</strong> </p> <pre> </pre> <p> <strong>Output</strong> </p> <pre> Colours are: Red, White, Black, Yellow </pre> <h3>2. Associative Array</h3> <p>In PHP, the user can associate any specific name with each array elements using the &apos;=&gt;&apos; symbol.</p> <p> <strong>Syntax</strong> </p> <pre> $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; </pre> <p> <strong>Example</strong> </p> <pre> <?php $marks[\'Reema \']=\'95\'; $marks[\'John\']=\'45\'; $marks [\'Rahul \']=\'20\'; echo \'Reema\'s Marks: \'.$marks [\'Reema \'].\' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 </pre> <h3>3. Multidimensional Array</h3> <p>Multidimensional arrays in PHP are also termed as &apos;array of arrays&apos;. It enabled the user to store array data in a tabular format. PHP multidimensional array can be expressed in the form of a matrix which is denoted by row * column.</p> <p> <strong>Syntax</strong> </p> <pre> $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); </pre> <p> <strong>Example</strong> </p> <pre> <?php $emp = array ( array (1,\'Reema\',95), array(2,\'john\',45), array(3,\'rahul\',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].\' \'; } echo \' <br/>&apos;; } ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> 1 Reema 95 2 john 45 3 rahul 20 </pre> <h2>5. Python</h2> <p>Python uses a module named &apos;Array&apos; to handle all the functions of Arrays in Python. It is helpful when the user wants to manipulate only particular data values. Given below are the keywords that are important to learn the concept of an array in Python:</p> <ul> <li>Element - Any data stored in an array is known an element.</li> <li>Index - Whenever an array stores any data, it has some numerical location known as index that is beneficial to identify the location of the element.</li> </ul> <p> <strong>Syntax</strong> </p> <pre> from array import * arrayName = array(typecode, [data_to_be_initialized]) </pre> <p> <strong>Example</strong> </p> <pre> import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) </pre> <p> <strong>Output</strong> </p> <pre> First array value: 20 Second array value: 40 Second last array value: 80 </pre> <hr></3></pre></arr.length;></pre></arr.length;i++)>

Matrices de objetos

Una matriz de objetos se construye de la misma manera que una matriz de elementos de datos de tipo primitivo.

Ejemplo

 // Java program to create, store and display values for one-dimensional // array of objects class Employee { public int id_no; public String name; Employee(int id_no, String name) { this.id_no = id_no; this.name = name; } } // The Elements of the array are objects of a class Employee. public class Array_Objects_Example { public static void main (String[] args) { // declares an Array of integers. Employee[] arr; // assigning space for 5 objects of type Employee. arr = new Employee[5]; // storing the value for the first element of the array arr[0] = new Employee(111,&apos;Varun&apos;); // storing the value for the second elements of the array arr[1] = new Employee(121,&apos;Sukla&apos;); // so on... arr[2] = new Employee(131,&apos;Virat&apos;); arr[3] = new Employee(141,&apos;Anuskha&apos;); arr[4] = new Employee(151,&apos;Mohit&apos;); // accessing the elements of the specified array for (int i = 0; i <arr.length; i++) system.out.println(\\'element at \\' + i : arr[i].id_no +\\' \\'+ arr[i].name); } < pre> <p> <strong>Output</strong> </p> <pre> Element at 0 : 111 Varun Element at 1 : 121 Sukla Element at 2 : 131 Virat Element at 3 : 141 Anuskha Element at 4 : 151 Mohit </pre> <h3>Multidimensional Arrays</h3> <p>Multidimensional arrays are termed &apos;arrays of arrays&apos; as they can hold each element of an array with the reference of another array. These are also known as Jagged Arrays. A multidimensional array is constructed by adding a set of square brackets ([]) per dimension.</p> <p> <strong>Syntax</strong> </p> <pre> int[][] intArray = new int[10][20]; //a 2D array or matrix int[][][] intArray = new int[10][20][10]; //a 3D array </pre> <p> <strong>Example to store values in a Multidimensional Array</strong> </p> <pre> arry[0][0]=10; arry[0][1]=20; arry[0][2]=30; arry[1][0]=40; arry[1][1]=50; arry[1][3]=60; arry[2][1]=70; arry[2][2]=80; arry[2][3]=90; </pre> <p> <strong>Example of Multidimensional Array</strong> </p> <pre> class multiDimensional_Example { public static void main(String args[]) { // declaring and storing data in 2-Dimensional array int arry[][] = { {12,17,19},{32,62,12},{37,34,32} }; // traversing and printing the 2-Dimensional array for (int i=0; i<3 3 ; i++) { for (int j="0;" < j++) system.out.print(arry[i][j] + \\' \\'); system.out.println(); } pre> <p> <strong>Output</strong> </p> <pre> 12 17 19 32 62 12 37 34 32 </pre> <h2>4. PHP</h2> <p>PHP array is an ordered map (holds elements on the base of the key-value). It is utilized to hold multiple values of a similar data type in a single variable.</p> <p>PHP contains 3 kinds of array that are as follows:</p> <ol class="points"> <li>Indexed Array</li> <li>Associative Array</li> <li>Multidimensional Array</li> </ol> <h3>1. Indexed Array</h3> <p>PHP index is described by an integer number that begins with 0 (default value). The PHP array can store any data type, such as numbers, characters, strings, and objects. All PHP array data are allocated an index number by default.</p> <p> <strong>Syntax to store values</strong> </p> <pre> $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; </pre> <p> <strong>Example</strong> </p> <pre> </pre> <p> <strong>Output</strong> </p> <pre> Colours are: Red, White, Black, Yellow </pre> <h3>2. Associative Array</h3> <p>In PHP, the user can associate any specific name with each array elements using the &apos;=&gt;&apos; symbol.</p> <p> <strong>Syntax</strong> </p> <pre> $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; </pre> <p> <strong>Example</strong> </p> <pre> <?php $marks[\\'Reema \\']=\\'95\\'; $marks[\\'John\\']=\\'45\\'; $marks [\\'Rahul \\']=\\'20\\'; echo \\'Reema\\'s Marks: \\'.$marks [\\'Reema \\'].\\' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 </pre> <h3>3. Multidimensional Array</h3> <p>Multidimensional arrays in PHP are also termed as &apos;array of arrays&apos;. It enabled the user to store array data in a tabular format. PHP multidimensional array can be expressed in the form of a matrix which is denoted by row * column.</p> <p> <strong>Syntax</strong> </p> <pre> $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); </pre> <p> <strong>Example</strong> </p> <pre> <?php $emp = array ( array (1,\\'Reema\\',95), array(2,\\'john\\',45), array(3,\\'rahul\\',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].\\' \\'; } echo \\' <br/>&apos;; } ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> 1 Reema 95 2 john 45 3 rahul 20 </pre> <h2>5. Python</h2> <p>Python uses a module named &apos;Array&apos; to handle all the functions of Arrays in Python. It is helpful when the user wants to manipulate only particular data values. Given below are the keywords that are important to learn the concept of an array in Python:</p> <ul> <li>Element - Any data stored in an array is known an element.</li> <li>Index - Whenever an array stores any data, it has some numerical location known as index that is beneficial to identify the location of the element.</li> </ul> <p> <strong>Syntax</strong> </p> <pre> from array import * arrayName = array(typecode, [data_to_be_initialized]) </pre> <p> <strong>Example</strong> </p> <pre> import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) </pre> <p> <strong>Output</strong> </p> <pre> First array value: 20 Second array value: 40 Second last array value: 80 </pre> <hr></3></pre></arr.length;>

Matrices multidimensionales

Las matrices multidimensionales se denominan 'matrices de matrices', ya que pueden contener cada elemento de una matriz con la referencia de otra matriz. También se conocen como matrices irregulares. Una matriz multidimensional se construye agregando un conjunto de corchetes ([]) por dimensión.

Sintaxis

 int[][] intArray = new int[10][20]; //a 2D array or matrix int[][][] intArray = new int[10][20][10]; //a 3D array 

Ejemplo para almacenar valores en una matriz multidimensional

 arry[0][0]=10; arry[0][1]=20; arry[0][2]=30; arry[1][0]=40; arry[1][1]=50; arry[1][3]=60; arry[2][1]=70; arry[2][2]=80; arry[2][3]=90; 

Ejemplo de matriz multidimensional

 class multiDimensional_Example { public static void main(String args[]) { // declaring and storing data in 2-Dimensional array int arry[][] = { {12,17,19},{32,62,12},{37,34,32} }; // traversing and printing the 2-Dimensional array for (int i=0; i<3 3 ; i++) { for (int j="0;" < j++) system.out.print(arry[i][j] + \\' \\'); system.out.println(); } pre> <p> <strong>Output</strong> </p> <pre> 12 17 19 32 62 12 37 34 32 </pre> <h2>4. PHP</h2> <p>PHP array is an ordered map (holds elements on the base of the key-value). It is utilized to hold multiple values of a similar data type in a single variable.</p> <p>PHP contains 3 kinds of array that are as follows:</p> <ol class="points"> <li>Indexed Array</li> <li>Associative Array</li> <li>Multidimensional Array</li> </ol> <h3>1. Indexed Array</h3> <p>PHP index is described by an integer number that begins with 0 (default value). The PHP array can store any data type, such as numbers, characters, strings, and objects. All PHP array data are allocated an index number by default.</p> <p> <strong>Syntax to store values</strong> </p> <pre> $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; </pre> <p> <strong>Example</strong> </p> <pre> </pre> <p> <strong>Output</strong> </p> <pre> Colours are: Red, White, Black, Yellow </pre> <h3>2. Associative Array</h3> <p>In PHP, the user can associate any specific name with each array elements using the &apos;=&gt;&apos; symbol.</p> <p> <strong>Syntax</strong> </p> <pre> $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; </pre> <p> <strong>Example</strong> </p> <pre> <?php $marks[\\'Reema \\']=\\'95\\'; $marks[\\'John\\']=\\'45\\'; $marks [\\'Rahul \\']=\\'20\\'; echo \\'Reema\\'s Marks: \\'.$marks [\\'Reema \\'].\\' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 </pre> <h3>3. Multidimensional Array</h3> <p>Multidimensional arrays in PHP are also termed as &apos;array of arrays&apos;. It enabled the user to store array data in a tabular format. PHP multidimensional array can be expressed in the form of a matrix which is denoted by row * column.</p> <p> <strong>Syntax</strong> </p> <pre> $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); </pre> <p> <strong>Example</strong> </p> <pre> <?php $emp = array ( array (1,\\'Reema\\',95), array(2,\\'john\\',45), array(3,\\'rahul\\',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].\\' \\'; } echo \\' <br/>&apos;; } ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> 1 Reema 95 2 john 45 3 rahul 20 </pre> <h2>5. Python</h2> <p>Python uses a module named &apos;Array&apos; to handle all the functions of Arrays in Python. It is helpful when the user wants to manipulate only particular data values. Given below are the keywords that are important to learn the concept of an array in Python:</p> <ul> <li>Element - Any data stored in an array is known an element.</li> <li>Index - Whenever an array stores any data, it has some numerical location known as index that is beneficial to identify the location of the element.</li> </ul> <p> <strong>Syntax</strong> </p> <pre> from array import * arrayName = array(typecode, [data_to_be_initialized]) </pre> <p> <strong>Example</strong> </p> <pre> import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) </pre> <p> <strong>Output</strong> </p> <pre> First array value: 20 Second array value: 40 Second last array value: 80 </pre> <hr></3>

4.PHP

La matriz PHP es un mapa ordenado (contiene elementos en la base del valor clave). Se utiliza para contener múltiples valores de un tipo de datos similar en una sola variable.

PHP contiene 3 tipos de matrices que son las siguientes:

  1. Matriz indexada
  2. Matriz asociativa
  3. Matriz multidimensional

1. Matriz indexada

El índice PHP se describe mediante un número entero que comienza con 0 (valor predeterminado). La matriz PHP puede almacenar cualquier tipo de datos, como números, caracteres, cadenas y objetos. A todos los datos de la matriz PHP se les asigna un número de índice de forma predeterminada.

Sintaxis para almacenar valores

 $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); 

O

 $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; 

Ejemplo

 

Producción

booleano a cadena java
 Colours are: Red, White, Black, Yellow 

2. Matriz asociativa

En PHP, el usuario puede asociar cualquier nombre específico con cada elemento de la matriz usando el símbolo '=>'.

Sintaxis

 $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); 

O

 $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; 

Ejemplo

 <?php $marks[\\'Reema \\']=\\'95\\'; $marks[\\'John\\']=\\'45\\'; $marks [\\'Rahul \\']=\\'20\\'; echo \\'Reema\\'s Marks: \\'.$marks [\\'Reema \\'].\\' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; 

Producción

 Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 

3. Matriz multidimensional

Las matrices multidimensionales en PHP también se denominan 'matriz de matrices'. Permitió al usuario almacenar datos de matriz en formato tabular. La matriz multidimensional de PHP se puede expresar en forma de matriz que se indica mediante fila * columna.

Sintaxis

 $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); 

Ejemplo

 <?php $emp = array ( array (1,\\'Reema\\',95), array(2,\\'john\\',45), array(3,\\'rahul\\',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].\\' \\'; } echo \\' <br/>&apos;; } ?&gt; 

Producción

 1 Reema 95 2 john 45 3 rahul 20 

5. Pitón

Python usa un módulo llamado 'Array' para manejar todas las funciones de Arrays en Python. Es útil cuando el usuario desea manipular sólo valores de datos particulares. A continuación se detallan las palabras clave que son importantes para aprender el concepto de matriz en Python:

  • Elemento: cualquier dato almacenado en una matriz se conoce como elemento.
  • Índice: siempre que una matriz almacena datos, tiene una ubicación numérica conocida como índice que es beneficiosa para identificar la ubicación del elemento.

Sintaxis

 from array import * arrayName = array(typecode, [data_to_be_initialized]) 

Ejemplo

 import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) 

Producción

 First array value: 20 Second array value: 40 Second last array value: 80