Requisito previo: Arrays en C/C++
Una array multidimensional se puede denominar como una array de arrays que almacena datos homogéneos en forma tabular. Los datos en arrays multidimensionales se almacenan en orden de fila principal.
CPP
// C++ Program to print the elements of a // Two-Dimensional array #include<iostream> using namespace std; int main() { // an array with 3 rows and 2 columns. int x[3][2] = {{0,1}, {2,3}, {4,5}}; // output each array element's value for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { cout << "Element at x[" << i << "][" << j << "]: "; cout << x[i][j]<<endl; } } return 0; }
C
// C Program to print the elements of a // Two-Dimensional array #include<stdio.h> int main(void) { // an array with 3 rows and 2 columns. int x[3][2] = {{0,1}, {2,3}, {4,5}}; // output each array element's value for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { printf("Element at x[%i][%i]: ",i, j); printf("%d\n",x[i][j]); } } return (0); } // This code is contributed by sarajadhav12052009
CPP
// C++ program to print elements of Three-Dimensional // Array #include <iostream> using namespace std; int main() { // initializing the 3-dimensional array int x[2][3][2] = { { { 0, 1 }, { 2, 3 }, { 4, 5 } }, { { 6, 7 }, { 8, 9 }, { 10, 11 } } }; // output each element's value for (int i = 0; i < 2; ++i) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 2; ++k) { cout << "Element at x[" << i << "][" << j << "][" << k << "] = " << x[i][j][k] << endl; } } } return 0; }
C
// C program to print elements of Three-Dimensional Array #include <stdio.h> int main(void) { // initializing the 3-dimensional array int x[2][3][2] = { { { 0, 1 }, { 2, 3 }, { 4, 5 } }, { { 6, 7 }, { 8, 9 }, { 10, 11 } } }; // output each element's value for (int i = 0; i < 2; ++i) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 2; ++k) { printf("Element at x[%i][%i][%i] = %d\n", i, j, k, x[i][j][k]); } } } return (0); } // This code is contributed by sarajadhav12052009
Publicación traducida automáticamente
Artículo escrito por GeeksforGeeks-1 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA