ARREGLOS BIDIMENSIONALES Ing Betty Surez Torres CONCEPTOS BSICOS
ARREGLOS BIDIMENSIONALES Ing. Betty Suárez Torres
CONCEPTOS BÁSICOS Una matriz es un array de 2 dimensiones. Declaración: int m[6][10]; Array bidimensional de 6 × 10 enteros (matriz) float arr[3][2][5]; Array tridimensional de 3× 2× 5 reales (cubo)
Ejemplo 01 #include <stdio. h> #define FILAS 2 #define COLUMNAS 3 void main() { float matriz[FILAS][COLUMNAS]; for(i=0; i<FILAS; i++){ for(j=0; j>COLUMNAS; j++){ printf(“Matriz [%d]: ”, i, j); scanf(“%d”, &matriz[i][j]); } } for(i=0; i<FILAS; i++){ for(j=0; j>COLUMNAS; j++){ printf("El valor de Matriz[%d] es %dn", fil, col, matriz[fil][col]); }
ARREGLOS BIDIMENSIONALES: OPERACIONES BÁSICAS CON MATRICES Acciones Resultados Íngreso for(i=o; i<n; i++){ for(j=0; j<n; j++){ cout<<“M[“<<i<<“]”<<“[“<<j<<“]: ”; cin>>matriz[i][j]; } } Escritura for(i=o; i<n; i++){ for(j=0; j<n; j++){ cout<<“M[“<<i<<“]”<<“[“<<j<<“]: ”<<matriz[i][j]; } } Suma for(i=o; i<n; i++){ for(j=0; j<n; j++){ c[i][j] = a[i][j] + b[i][j]; Producto escalar for(i=o; i<n; i++){ for(j=0; j<n; j++){ c[i][j] = a[i][j] * numero } }
MÉTODOS DE BÚSQUEDA DE DATOS EN MATRICES: BÚSQUEDA SECUENCIAL
#include <iostream> #include <conio. h> using namespace std; void main (void) { int posf, posc; int a[50], n, i, j, x, f, c; cout<<"INGRESAR EL NUMERO DE FILAS DE LA MATRIZ: "; cin>>f; cout<<endl; cout<<"INGRESAR EL NUMERO DE COLUMNAS DE LA MATRIZ: "; cin>>c; cout<<endl; for(i=0; i<f; i++){ for(j=0; j<c; j++){ cout<<"Ingresar elemento M["<<i+1<<j+1<<"]: "; cin>> a[i][j]; cout<<endl; } } cout<<"INGRESAR ELEMENTO A BUSCAR EN EL ARRAY: "; cin>>x; cout<<endl; for(i=0; i<f; i++){ for(j=0; j<c; j++){ if(a[i][j]==x){ posf=i; posc=j; cout<<endl<<"La posición es: "<<posf+1<<", "<<posc+1<<endl; } } } cout<<endl<<"El elemento buscado es: "<<x<<endl; getch(); }
- Slides: 6