Diferencia entre revisiones de «matriz»

De ArduWiki
Saltar a: navegación, buscar
(Ejemplo 1)
(Ejemplo 2)
Línea 27: Línea 27:
 
== Ejemplo 2 ==
 
== Ejemplo 2 ==
 
<syntaxhighlight lang="c++">
 
<syntaxhighlight lang="c++">
int matriz[][6] = {{2019,7,14,8,0,0},{2019,7,19,8,0,0},{2019,7,22,8,0,0}};
+
const int matriz[][6] = {
 +
  {2019,7,14,8,0,0},
 +
  {2019,7,19,8,0,0},
 +
  {2019,7,22,8,0,0}
 +
};
 +
 
 
void setup(){
 
void setup(){
 
   Serial.begin(9600);
 
   Serial.begin(9600);
   for (i=0; i<3; i++){
+
   for (byte i=0; i<3; i++){
       for (j=0; j<7; j++){
+
       for (byte j=0; j<6; j++){
         Serial.print();
+
         Serial.print(matriz[i][j]);
 
       }
 
       }
 +
      Serial.println();
 
   }
 
   }
 
}
 
}
 +
 +
void loop(){
 +
  //Nada
 +
}
 +
</syntaxhighlight>
 +
 +
== Ejemplo 3 ==
 +
<syntaxhighlight lang="c++">
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Revisión del 20:21 5 sep 2019

Descripcion

Una matriz es una variable que puede contener multiples elementos del mismo tipo.

Sintaxis

tipo nombre[] = {elemento1, elemento2...};
tipo nombre[][n] = {{1,2,3},{4,5,6},{7,8,9}};

Parámetros

tipo
puede ser char, byte, int, unsigned int, long, unsigned long o float.
nombre
es el nombre que se asignara a la matriz
n
Es el numero de elementos

Comentarios

  • En un matriz se puede obviar el numero de elementos (filas), pero en una matriz bidireccional es obligatorio indicar el numero de columnas.

Advertancia

Nada.

Ejemplo 1

byte matriz1[] = {21,250,2,64};
int matriz2[] = {2019,7,14,8,0,0};

Ejemplo 2

const int matriz[][6] = {
   {2019,7,14,8,0,0},
   {2019,7,19,8,0,0},
   {2019,7,22,8,0,0}
};

void setup(){
   Serial.begin(9600);
   for (byte i=0; i<3; i++){
      for (byte j=0; j<6; j++){
         Serial.print(matriz[i][j]);
      }
      Serial.println();
   }
}

void loop(){
   //Nada
}

Ejemplo 3

Vea también

Referencias externas