universidad técnica de ambato
DESCRIPTION
VECTORES Y MATRICESTRANSCRIPT
![Page 1: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/1.jpg)
UNIVERSIDAD
TÉCNICA DE AMBATO
FACULTAD DE CIENCIAS
HUMANAS Y DE LA EDUCACIÓN
CARRERA DE dOCENCIA
iNFORMÁTICA
![Page 2: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/2.jpg)
VECTORES Y MATRICES
ALUMNO: DIEGO RODRIGO JURADO ORTUÑO
TUTORA: MSC. ING. WILMA GAVILANEZ
MODULO PROGRAMACIÓN
SEMESTRE: TERCER SEMESTRE
![Page 3: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/3.jpg)
VECTOR
Un vector, también llamado ARRAY (ARREGLO) unidimensional, es una estructura de datos que permite agrupar elementos del mismo tipo y almacenarlos en un solo bloque de memoria juntos, uno despues de otro.
A este grupo de elementos se les identifica por un mismo nombre y la posición en la que se encuentran. La primera posición del array es la posición 0.
![Page 4: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/4.jpg)
SINTAXIS
Podríamos agrupar en un array una serie de elementos de tipo enteros, flotantes, caracteres, objetos, etc. Crear un vector en c++ es sencillo, seguimos la siguiente sintaxix:
Tipo nombre[tamaño]; Aula[25]; int a[5];//Vector de 5 enteros float b[5];//vector de 5 flotantes
![Page 5: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/5.jpg)
Podríamos también inicializar el vector en la declaración:
int a[] = {5,15,20,25,30};
float b[] = {10.5,20.5,30.5,12.5,50.5};
Producto product[] =
{celular,calculadora,camara,ipod,usb};
![Page 6: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/6.jpg)
Matrices Una matriz es un vector de vectores o un
también llamado array bidimensional. La manera de declarar una matriz es c++ es similar a un vector:
ver fuenteImprimir? int matriz[filas][colns];
int es el tipo de dato, matriz es el nombre del todo el conjunto de datos y debo de especificar el numero de filas y columnas. Las matrices también pueden ser de distintos tipos de datos como char, float, double, etc.
![Page 7: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/7.jpg)
Las matrices en c++ se almacenan al igual que los vectores en posiciones consecutivas de memoria. Usualmente uno se hace la idea que una matriz es como un tablero. Pero internamente el manejo es como su definicion lo indica, un vector de vectores, es decir, los vectores estan uno detras del otro juntos.
![Page 8: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/8.jpg)
La forma de acceder a los elementos de la matriz es utilizando su nombre e indicando los 2 subindices que van en los corchetes. Si Coloco int matriz[2][3]=10; //estoy asignando al cuarto elemento de la tercera fila el valor 10. No olvidar que tanto filas como columnas se enumeran a partir de 0.
Bueno y para recorrer una matriz podemos usar igualmente un bucle. En este caso 2 for:
for(int i=0;i<filas;i++){for(int j=0;j<colns;j++){matriz[i][j] = i % j;}}
![Page 9: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/9.jpg)
Punteros
PUNTEROSEl valor de todas las variales que manejamos en nuestros programas se almacenan en memoria y tienen una dirección. Un puntero es una variable especial que apunta a la dirección de memoria de una variable. El puntero tiene a su vez su propia dirección. Todas estas direcciones tienen un formato hexadecimal.
![Page 10: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/10.jpg)
Los punteros son herramientas muy poderosas con muchas utilidades y enormes ventajas como veremos más adelante. A grandes rasgos, un puntero me permite desplazarme en la memoria, apuntar, re direccionar a ciertas variables, funciones, métodos, objetos sin necesidad de mover grandes bloques de datos, lo cual nos ahorra muchísimo el consumo de memoria en los programas.
![Page 11: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/11.jpg)
Puntero
Un puntero se debe declarar de acuerdo al tipo de dato al que apunta. Ejem:
int *var; //Un puntero llamado var que podrá apuntar a cualquier variable de tipo entero.
char *u;//puntero de tipo char Persona *per;//puntero de tipo persona
![Page 12: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/12.jpg)
EJERCICIOS…
![Page 13: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/13.jpg)
EJERCICIO 1
![Page 14: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/14.jpg)
Diseñe un programa que me permita generar la serie de fibonaci
//Matriz que genera la serie del fibonacci#include<conio.h>#include<stdio.h>int i,j, N, vec1[10], mat[10][10];int main(){ int a=0, b=0, c=0, k; a=-1; b=1; clrscr(); gotoxy(2,2);cprintf("Ingrese el tamanio de la matriz: "); scanf("%d",&N); //mat[0][0] = c; // Ingreso de datos a la matriz for(i=0; i<N; i++) { k = 0; for(j=0; j<N; j++, k+=4) { c = a+b; a = b; b = c; mat[i][j] = c; gotoxy(5+k, 4+i); printf("%d", mat[i][j]); } }
getch();return 0;}
![Page 15: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/15.jpg)
Sin errores
![Page 16: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/16.jpg)
Ingresamos el tamaño de la matriz
![Page 17: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/17.jpg)
EJERCICIO 2
![Page 18: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/18.jpg)
DISEÑE UN PROGRAMA PARA
INGRESAR DATOS CON
ESTRUCTURAS DE DATOS
![Page 19: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/19.jpg)
#include<stdio.h>#include<conio.h>#include<stdlib.h>struct datos1{char cedula[15];char nombres[15];char apellidos[15];int edad;}datos[10]; void borde() { int i; for(i=2;i<=78;i++) { gotoxy(i,2);printf("*"); gotoxy(i,24);printf("*"); } for(i=2;i<=24;i++) { gotoxy(2,i);printf("*"); gotoxy(78,i);printf("*"); }} void main() { int edad ,op,i,n,fila; do{ clrscr(); borde();
gotoxy(10,3);printf("PROGRAMA PARA INGRESAR DATOS CON ESTRUCTURAS DE DATOS"); gotoxy(8,4);printf("Ingrese el numero de ingresos:");scanf("%d",&n); fila=7; for(i=1;i<=n;i++) { flushall(); gotoxy(8,5);printf("CEDULA NOMBRES APELLIDOS EDAD"); gotoxy(8,fila);gets(datos[i].cedula);gotoxy(25,fila);gets(datos[i].nombres);gotoxy(40,fila);gets(datos[i].apellidos);gotoxy(60,fila);scanf("%d",& edad);fila=fila+1;}gotoxy(30,13);printf("SALIDA DE DATOS");fila=14;for(i=1;i<=n;i++){gotoxy(8,fila);puts(datos[i].cedula);gotoxy(25,fila);puts(datos[i].nombres);gotoxy(40,fila);puts(datos[i].apellidos);gotoxy(60,fila);printf("%d", edad);fila=fila+1;}gotoxy(10,22);printf("Ingrese 1para continuar y 0 para salir:");scanf("%d",&op);}while(op==1);getch();}
![Page 20: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/20.jpg)
Compilamos el programa
![Page 21: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/21.jpg)
EJECUTAMOS EL PROGRAMA
![Page 22: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/22.jpg)
EJERCICIO 2
![Page 23: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/23.jpg)
DISEÑE UN PROGRAMA QUE ME PERMITA FORMAR UNA MATRIZ EN X
#include<stdio.h>#include<conio.h>void main(){int i,j,col,fila,lim,op,a,x;int matriz1[10][10];do{clrscr();for(i=3;i<=80;i++){gotoxy(i,3);printf("*");gotoxy(i,50);printf("*");}for(i=3;i<=50;i++){gotoxy(3,i);printf("*");gotoxy(80,i);printf("*");}col=8;fila=8;gotoxy(20,3);printf("PROGRAMA PARA FORMAR UNA MATRIS EN
X");gotoxy(10,5);printf("Ingrese el limite:");scanf("%d",&lim);gotoxy(10,7);printf("ENTRADA SALIDA DIAGONAL
");for(i=1;i<=lim;i++){for(j=1;j<=lim;j++){gotoxy(col,fila);scanf("%d",&matriz1[i][j]);col=col+2;}fila=fila+1;col=8;}col=25;fila=8;
for(i=1;i<=lim;i++){for(j=1;j<=lim;j++){col=col+2;gotoxy(col,fila);printf("%d",matriz1[i][j]);}fila=fila+1;col=25;}col=50;fila=8;for(i=1;i<=lim;i++){for(j=1;j<=lim;j++){if(i==j){gotoxy(col,fila);printf("%d",matriz1[i][j]);col=col+5;fila=fila+1;}for(a=1;a<=lim;a++){gotoxy(col,fila);printf("%d",matriz1[a][x]);x=lim-1;
}}}gotoxy(10,45);printf("INGRESE 1 PARA CONTINUAR Y 0 PARA SALIR");scanf("%d",&op);}while(op==1);getch();}
![Page 24: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/24.jpg)
Compilamos el programa
![Page 25: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/25.jpg)
EJECUTAMOS EL PROGRAMA
![Page 26: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/26.jpg)
EJERCICIO 3
![Page 27: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/27.jpg)
DISEÑE UN PROGRAMA QUE ME PERMITA REALIZAR EL PRODUCTO DE UNA MATRIZ
#include<stdio.h>#include<conio.h>int lim,col,col1,col2,fila,fila1,fila2,h,i,j,op,a;int matriz1[20][20],matriz2[20]
[20],matriz3[20][20];void borde(){for(i=2;i<=25;i++){gotoxy(2,i);printf("*");gotoxy(78,i);printf("*");}for(i=2;i<=78;i++){gotoxy(i,2);printf("*");gotoxy(i,25);printf("*");}}void ingreso(){col=5;fila=10;for(i=1;i<=lim;i++){ for(j=1;j<=lim;j++) { gotoxy(col,fila);scanf("%d",&matriz1[i][j]); col=col+5; }
col=5;fila=fila+1;}col1=25;fila1=10;for(i=1;i<=lim;i++){ for(j=1;j<=lim;j++) {
gotoxy(col1,fila1);scanf("%d",&matriz2[i][j]); col1=col1+5; }col1=25;fila1=fila1+1;}}void producto(){col2=42;fila2=10;for(i=0;i<=lim;i++){for(j=0;j<=lim;j++){matriz3[i][j]=0;for(h=0;h<=lim;h++){matriz3[i][j]=matriz3[i][j]+matriz1[i][h]*matriz2[h][j];}}
}for(i=1;i<=lim;i++){for(h=1;h<=lim;h++){gotoxy(col2,fila2);printf("%d",matriz3[i][h]);col2=col2+4;}col2=42;fila2=fila2+1;}}void main(){do{clrscr();borde();gotoxy(20,3);printf("PRODUCTO ALGEBRAICO DE UNA MATRIZ");gotoxy(7,5);printf("Ingrese el limite: ");scanf("%d",&lim);gotoxy(5,7);printf("MATRIZ_1");gotoxy(25,7);printf("MATRIZ_2");gotoxy(40,7);printf("PRODUCTO");ingreso();producto();gotoxy(8,22);printf("Ingrese 1 para continuar y 0 para salir:");scanf("%d",&op);}while(op==1);getch();
}
![Page 28: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/28.jpg)
Compilamos el programa
![Page 29: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/29.jpg)
EJECUTAMOS EL PROGRAMA
![Page 30: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/30.jpg)
EJERCICIO 4
![Page 31: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/31.jpg)
#include<conio.h>#include<stdio.h>void main(){int ma[50][50],vc[50],q,y,n,l,a,va,i,j,k,x,c,f;clrscr(); textcolor(6);gotoxy (10,6); cprintf("INGRESE
UN LIMITE "); scanf("%d",&n);f=7;va=0;c=10;for (i=1;i<=n;i++){
c=c+3;for (j=1;j<=n;j++){
f=f+2;va=va+5;ma[i][j]=va;gotoxy(c,f);printf("%d",ma[i][j]);
}
f=7;}/*principal*/
c=10;f=19;for(i=1;i<=n;i++)
{c=c+3;for(j=1;j<=n;j++) {
f=f+1;if(i==j)
{
} } f=19;}
/*secundaria*/ k=n; a=2;
for (i=1;i<=n;i++){a=a+2; textcolor(13);gotoxy(10+a,32-i);cprintf("%d",ma[i][k]); vc[i]=ma[i][k];k=k-1;} y=7; for (x=1;x<=q;x++){ y=y+1; gotoxy(48,y);cprintf("%d",vc[x]);}
}/*----------------------------------*/f=7;va=0;
c=30;for (i=1;i<=n;i++){
c=c+3;for (j=1;j<=n;j++){
f=f+2;va=va+7;ma[i][j]=va;gotoxy(c,f);printf("%d",ma[i][j]);
}
f=7;}/*primaria2*/
c=30;f=19;
for(i=1;i<=n;i++){
c=c+3;for(j=1;j<=n;j++){
f=f+1;
if(i==j){ textcolor(10);
gotoxy(c,f);cprintf("%d",ma[i][j]); vc[i]=ma[i][j];
} }
f=19;}
/*secundaria2*/k=n;for (i=1;i<=n;i++){
textcolor(13);gotoxy(35+i,32-i);cprintf("%d",ma[i][k]);
vc[i]=ma[i][k];
k=k-1;} q=n*4;/* y=7;for (x=1;x<=q;x++){ y=y+1; gotoxy(48,y);cprintf("%d",vc[x]);}*/
getch();
![Page 32: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/32.jpg)
Compilamos el programa
![Page 33: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/33.jpg)
EJECUTAMOS EL PROGRAMA
![Page 34: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/34.jpg)
EJERCICIO 5
![Page 35: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/35.jpg)
PROGRAMA PARA REALIZAR OPERACIONES CON VECTORES (PRUEBA 1)
# include<stdio.h>#include<conio.h>void main(){int v1[20], v2[20], v3[20], v4[20], i , lim, par, impar,col,fil;clrscr();gotoxy(25,4);printf("OPERACIONES ENTRE VECTORES");gotoxy(10,6);printf("INGRESE EL LIMITE ==> : ");scanf("%d",
&lim);do { gotoxy(25,8); printf(" "); gotoxy(10,8);printf("INGRESE EL NUMERO PAR ==> : ");
scanf("%d",&par); } while(par % 2==1);do { gotoxy(25,10); printf(" "); gotoxy(10,10);printf("INGRESE EL NUMERO IMPAR ==> : ");
scanf("%d",&impar); } while(impar % 2==0);col=15;fil=20;for(i=1;i<=lim;i++){v1[i]=par*i;gotoxy(14,15);printf("V1");gotoxy(col,fil);printf("%d",v1[i]);fil=fil+1;}
fil=20;for(i=1;i<=lim;i++){v2[i]=impar*i;gotoxy(20,15);printf("V2");gotoxy(col+5,fil);printf("%d",v2[i]);fil=fil+1;}
fil=20;for(i=1;i<=lim;i++){v3[i]=v1[i]*v2[i];gotoxy(25,15);printf("V3");gotoxy(col+10,fil);printf("%d",v3[i]);fil=fil+1;}
fil=20;for(i=lim;i>0;i--){ v3[i]=v1[i]*v2[i];gotoxy(38,15);printf("V4");gotoxy(col+20,fil);printf("%d",v3[i]);fil=fil+1;
}
getch();}
![Page 36: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/36.jpg)
Compilamos el programa
![Page 37: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/37.jpg)
EJECUTAMOS EL PROGRAMA
![Page 38: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/38.jpg)
EJERCICIO 6
![Page 39: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/39.jpg)
EXAMEN
Diseñe un programa utilizando Matrices y Funciones que permita:
1. Ingresar n elementos en una matriz con datos entre 5 y 35, excluyendo las diagonales
2. principal y secundaria, en dónde la diagonal principal se llena con la serie del Fibonnaci
3. y la diagonal secundaria con el factorial de los números ascendentes iniciando en 3.
4. Recorra la matriz y guarde los datos de la diagonal principal en las posiciones pares del vector
5. y los datos de la diagonal segundaria en las posiciones impares del vector.
6. Presente como resultado el vector origen resultante y el mismo vector preséntelo impreso en forma descendente
![Page 40: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/40.jpg)
Compilamos el programa
![Page 41: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/41.jpg)
EJECUTAMOS EL PROGRAMA
![Page 42: Universidad técnica de ambato](https://reader035.vdocumento.com/reader035/viewer/2022062706/557b1e8bd8b42a796a8b47ae/html5/thumbnails/42.jpg)
GRACIAS
POR SU ATENCIÓN