top of page

TAREA REALIZADA EN CLASES Y TAMBIEN LA TAREA DOMICILIARIA

3 PROBLEMAS DE MATRICES

#include<iostream>
#include<math.h>
using namespace std;

int n;

// Función para imprimir una matriz
void imprimirMatriz(float matriz[3][3], int filas, int columnas) {
    for(int i = 0; i < filas; ++i) {
        for(int j = 0; j < columnas; ++j) {
            cout << matriz[i][j] << " ";
        }
        cout << endl;
    }
}

// Función para realizar la división de matrices
void dividirMatrices(float matriz1[3][3], float matriz2[3][3], int filas, int columnas) {
    float resultado[3][3];
    
    for(int i = 0; i < filas; ++i) {
        for(int j = 0; j < columnas; ++j) {
            if (matriz2[i][j] == 0) {
                cout << "No se puede dividir por cero." << endl;
                return;
            }
            resultado[i][j] = matriz1[i][j] / matriz2[i][j];
        }
    }
    
    cout << "Resultado de la división de matrices:" << endl;
    imprimirMatriz(resultado, filas, columnas);
}

// Función para realizar la inversa de una matriz
void matrizInversa(float matriz[3][3], int filas, int columnas) {
    // Aquí puedes implementar el cálculo de la inversa de la matriz
    // Esta función es solo un esquema, necesitarás implementar el algoritmo adecuado.
    cout << "Inversa de la matriz:" << endl;
    imprimirMatriz(matriz, filas, columnas);
}

// Función para generar la matriz identidad
void matrizIdentidad(int filas, int columnas) {
    float identidad[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
    
    cout << "Matriz Identidad:" << endl;
    imprimirMatriz(identidad, filas, columnas);
}

int main() {
    n = 100;
    
    while (n != 0) {
        int opcion;
        cout << "   M E N U    P R I N C I P A L \n";
        cout << " -------------------------------\n";
        cout << "1. División de matrices\n";
        cout << "2. Inversa de la matriz\n";
        cout << "3. Identidad de la matriz\n";
        cout << "4. Salir\n";
        cout << endl;
        cout << "Ingrese la opcion: ";
        cin >> opcion;
        
        switch(opcion) {
            case 1: {
                float matriz1[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
                float matriz2[3][3] = {{9, 8, 7}, {6, 5, 4}, {3, 2, 1}};
                dividirMatrices(matriz1, matriz2, 3, 3);
            } break;
            case 2: {
                float matriz[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
                matrizInversa(matriz, 3, 3);
            } break;
            case 3: {
                matrizIdentidad(3, 3);
            } break;
            case 4: {
                n = 0;
            } break;
            default:
                cout << "Opción no válida." << endl;
        }
        
        cout << "Si desea salir, ingrese el número <0>: ";
        cin >> n;
        cout << endl;
    }
    
    return 0;
}
 

bottom of page