top of page
Codigo completo
Para ejecutar el codigo dirigirse esta dirección 
Al ingresar al compilador borra el codigo existente y pega el nuevo codigo para ejecutar correctamente
#include <iostream>
using namespace std;

int A[3][3];
int B[3][3];
int C[3][3];

void ASIGNAR();
void MOSTRAR();
void PROMEDIO();
void SUMA_MATRICES();
void DETERMINANTE();

int main() {
    int opcion;

    do {
        cout << "    MENU PRINCIPAL MATRICES \n " << endl;
        cout << " ----------------------------" << endl;
        cout << "  [1] ASIGNAR VALORES A LA MATRIZ A[][]" << endl;
        cout << "  [2] MOSTRAR VALORES DE LA MATRIZ A[][]" << endl;
        cout << "  [3] CALCULAR PROMEDIO DE LOS ELEMENTOS DE LA MATRIZ A[][]" << endl;
        cout << "  [4] SUMA DE DOS MATRICES A + B" << endl;
        cout << "  [5] DETERMINANTE DE LA MATRIZ" << endl;
        cout << "  [0] SALIR" << endl;

        cout << "\n  INGRESE UNA OPCION <> ";
        cin >> opcion;
        cout << " ----------------------------" << endl;

        switch (opcion) {
            case 1:
                cout << "*************** \n ";
                cout << "1.ASIGNACION \n";
                ASIGNAR(); 
                break;
                
            case 2:
                cout << "*************** \n ";
                cout << "2.MOSTRAR ELEMENTOS DE LA MATRIZ \n";
                MOSTRAR();
                cout << "************************ \n ";
                break;
                
            case 3:
                cout << "*************** \n ";
                cout << "3.PROMEDIO DE LOS ELEMENTOS  \n";
                PROMEDIO();
                cout << "************************ \n ";
                break;
                
            case 4:
                cout << "*************** \n ";
                cout << "4.SUMA DE DOS MATRICES \n";
                SUMA_MATRICES();
                cout << "************************ \n ";
                break;
            
            case 5:
                cout << "*************** \n ";
                cout << "5.DETERMINANTE DE LA MATRIZ \n";
                DETERMINANTE();
                cout << "************************ \n ";
                break;
                
            case 0:
                cout << "Saliendo del programa.\n";
                break;
                
            default:
                cout << "Opcion no valida. Intente de nuevo.\n";
                break;
        }

    } while (opcion != 0);

    return 0;
}

void ASIGNAR() {
    cout << "LLENADO DE ELEMENTOS DE LA MATRIZ A[3][3]  \n";
    for (int i = 1; i <= 3; ++i) {
        for (int j = 1; j <= 3; ++j) {
            cout << " A[" << i << "][" << j << "] = ";
            cin >> A[i-1][j-1];
        }
    }
}

void MOSTRAR() {
    cout << "MATRIZ A[3][3]:\n";
    for (int i = 1; i <= 3; ++i) {
        for (int j = 1; j <= 3; ++j) {
            cout << A[i-1][j-1] << " ";
        }
        cout << endl;
    }
}

void PROMEDIO() {
    int suma = 0;
    for (int i = 1; i <= 3; ++i) {
        for (int j = 1; j <= 3; ++j) {
            suma += A[i-1][j-1];
        }
    }

    double promedio = static_cast<double>(suma) / 9.0;
    cout << "El promedio de los elementos de la matriz A[][] es: " << promedio << endl;
}

void SUMA_MATRICES() {
    cout << "LLENADO DE ELEMENTOS DE LA MATRIZ B[3][3]  \n";
    for (int i = 1; i <= 3; ++i) {
        for (int j = 1; j <= 3; ++j) {
            cout << " B[" << i << "][" << j << "] = ";
            cin >> B[i-1][j-1];
        }
    }

    cout << "SUMA DE MATRICES A + B:\n";
    for (int i = 1; i <= 3; ++i) {
        for (int j = 1; j <= 3; ++j) {
            C[i-1][j-1] = A[i-1][j-1] + B[i-1][j-1];
            cout << C[i-1][j-1] << " ";
        }
        cout << endl;
    }
}

void DETERMINANTE()
{
    int det = 0;

    for (int i = 1; i <= 3; ++i)
    {
        int product = 1;
        for (int j = 1; j <= 3; ++j)
        {
            product *= A[(i + j) % 3][(j + i - 1) % 3];
        }
        det += product;
    }

    for (int i = 1; i <= 3; ++i)
    {
        int product = 1;
        for (int j = 1; j <= 3; ++j)
        {
            product *= A[(3 - i + j) % 3][(j + i - 1) % 3];
        }
        det -= product;
    }

    cout << "La determinante de la matriz A[][] es: " << det << endl;
}
bottom of page