Академический Документы
Профессиональный Документы
Культура Документы
Conceptos bsicos
Los arrays ms usuales son los de
dos
dimensiones,
conocidos
tambin por el nombre de tablas
o matrices.
Sin embargo, es posible crear
arrays de tantas dimensiones
como requieran sus aplicaciones,
esto es, tres, cuatro o ms
dimensiones.
Un
array de dos dimensiones
equivale a una tabla con mltiples
filas y mltiples columnas tal
como se precia en la siguiente
figura.
Matrices
Declaracin de Matrices
Una
matriz tiene filas y
columnas,
entonces,
se
debe de indicar el nmero
de filas y columnas que
poseer la matriz.
El formato general para la
declaracin de una variable
de
tipo
vector
es
el
siguiente:
Matrices
Declaracin de Matrices
De
la sintaxis anterior
decir:
Tipo_de_Datos
mat1, , matN
[tFil]
podemos
int.
float.
double.
Nombre de la matriz.
Tamao de fila.
Matrices
Declaracin de Matrices
Algunos ejemplos:
// Se declaran dos matrices mat1 y
mat2
// de tipo entero y
flotante de
dimensiones 3x3.
int mat1[3][3];
float mat2[3][3];
Matrices
mat1[0][0]
Columna
j=2
Columna
j=0
Columna
j=1
Declaracin de Matrices
Analizando las matrices anteriores
Fila
i=0
Fila
i=1
Fila
i=2
mat1
Ing. Zegarra Henry
mat1[1][2]
Matrices
Ingresado datos
Matrices
Ingresando
datos a una
matriz.
Matrices
n_fil
n_col
Matrices
n_fil
n_col
0,0
0,2
0,1
1,0
1,2
1,1
Matrices
n_fil
n_col
0,0
0,2
0,1
1,0
1,2
1,1
Matrices
n_fil
n_col
0,0
0,2
0,1
1,0
1,2
1,1
Matrices
n_fil
n_col
0,0
0,2
0,1
1,0
1,2
1,1
Matrices
n_fil
n_col
0,0
0,2
0,1
1,0
1,2
1,1
Matrices
n_fil
n_col
0,0
0,2
0,1
1,0
1,2
1,1
Matrices
n_fil
n_col
0,0
0,212
0,1
1,0
1,2
1,1
Matrices
n_fil
n_col
0,0
0,212
0,1
1,0
1,2
1,1
Matrices
n_fil
n_col
0,0
0,212
0,1
1,0
1,2
1,1
Matrices
n_fil
n_col
0,0
0,212
0,1
1,0
1,2
1,1
-1
Matrices
n_fil
n_col
0,0
0,212
0,1
1,0
1,2
1,1
-1
Matrices
n_fil
n_col
0,0
0,212
0,1
1,0
1,2
1,1
-1
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
0<2
i=0;
while( i<n_fil) (VERDADERO)
{
2<3
j=0;
(VERDADERO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,2
1,1
-1
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
0<2
i=0;
while( i<n_fil) (VERDADERO)
{
2<3
j=0;
(VERDADERO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,2
1,1
-1
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
0<2
i=0;
while( i<n_fil) (VERDADERO)
{
j=0;
3<3 (FALSO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,2
1,1
-1
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
0<2
i=0;
while( i<n_fil) (VERDADERO)
{
j=0;
3<3 (FALSO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,2
1,1
-1
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
1<2
i=0;
while( i<n_fil) (VERDADERO)
{
j=0;
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,2
1,1
-1
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
1<2
i=0;
while( i<n_fil) (VERDADERO)
{
j=0;
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,2
1,1
-1
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
1<2
i=0;
while( i<n_fil) (VERDADERO)
{
0<3
j=0;
(VERDADERO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,2
1,1
-1
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
1<2
i=0;
while( i<n_fil) (VERDADERO)
{
0<3
j=0;
(VERDADERO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
1<2
i=0;
while( i<n_fil) (VERDADERO)
{
0<3
j=0;
(VERDADERO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
1<2
i=0;
while( i<n_fil) (VERDADERO)
{
1<3
j=0;
(VERDADERO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
1<2
i=0;
while( i<n_fil) (VERDADERO)
{
1<3
j=0;
(VERDADERO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
1<2
i=0;
while( i<n_fil) (VERDADERO)
{
1<3
j=0;
(VERDADERO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
1<2
i=0;
while( i<n_fil) (VERDADERO)
{
2<3
j=0;
(VERDADERO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
1<2
i=0;
while( i<n_fil) (VERDADERO)
{
2<3
j=0;
(VERDADERO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
1<2
i=0;
while( i<n_fil) (VERDADERO)
{
2<3
j=0;
(VERDADERO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
1<2
i=0;
while( i<n_fil) (VERDADERO)
{
j=0;
3<3 (FALSO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
1<2
i=0;
while( i<n_fil) (VERDADERO)
{
j=0;
3<3 (FALSO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Ingresando datos a una matriz.
cout<<"Ingrese nmero de filas (Max. 50): ";
cin>>n_fil; // Nueva dimensin de fila
cout<<"Ingrese nmero de columnas (Max. 50):
";
cin>>n_col; // Nueva dimensin de columna
cout<<"Ingrese datos a la Matriz\n ";
i=0;
2<2 (FALSO)
while( i<n_fil)
{
j=0;
3<3 (FALSO)
while( j<n_col)
{
cout<<Pos["<<i<<"]["<<j<<"] = ";
cin>>mat1[i][j];
j++;
}
i++;
}
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo datos
Matrices
Imprimiendo datos
de una matriz.
Matrices
Imprimiendo la matriz
mat1 =
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[-1]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[-1]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[-1]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[-1]
[3]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[-1]
[3]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[-1]
[3]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
_
[-1]
[3]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
_
[-1]
[3]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
_
[-1]
[3]
1<2
i=0;
while( i<n_fil) (VERDADERO)
{
j=0;
while( j<n_col)
{
cout<<\t["<<mat1[i][j]<<]";
j++;
}
0 cout<<endl;
0 i++;
}
0
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
_
[-1]
[3]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
_
[-1]
[3]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[11]
[-1]
[3]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[11]
[-1]
[3]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[11]
[-1]
[3]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[11]
[-1]
[3]
[100]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[11]
[-1]
[3]
[100]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[11]
[-1]
[3]
[100]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[11]
[-1]
[3]
[100] [-11]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[11]
[-1]
[3]
[100] [-11]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[11]
[-1]
[3]
[100] [-11]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[11]
[-1]
[3]
[100] [-11]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[11]
[-1]
[3]
[100] [-11]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Matrices
Imprimiendo la matriz
mat1 =
[12]
[11]
[-1]
[3]
[100] [-11]
n_fil
n_col
0,0
0,212
0,1
1,0
1,211
1,1
-1
100
-11
Resumiendo
Matrices con
Procedimient
os
Matrices con
Procedimient
os