Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <ctime>
- using namespace std;
- //void MatrizIndentidad()
- //{
- //
- // int Matriz_I[12][12];
- //
- // for (int fila = 0; fila < 12; fila++)
- // {
- // for (int columna = 0; columna < 12; columna++)
- // {
- // if (fila == columna)
- // Matriz_I[fila][columna] = 1;
- // else
- // Matriz_I[fila][columna] = 0;
- //
- // cout << Matriz_I[fila][columna];
- // }
- // cout << endl;
- // }
- //}
- //void MatrizA( int m[][12], int _n, int _n2)
- //{
- //
- // srand(time(NULL));
- // int Matriz_A[12][12];
- //
- // for (int fila = 0; fila < _n; fila++)
- // {
- // for (int columna = 0; columna < 12; columna++)
- // {
- // Matriz_A[fila][columna] = rand() % 10 + 1;
- //
- // cout << Matriz_A[fila][columna] << " ";
- // }
- //
- // cout << endl;
- // }
- //
- //}
- //void MatrizB()
- //{
- // srand(time(NULL));
- // int Matriz_B[12];
- //
- // for (int fila = 0; fila < 12; fila++)
- // {
- // Matriz_B[fila] = rand() % 50 + 10;
- //
- // cout << Matriz_B[fila] << endl;
- // }
- //}
- void main()
- {
- srand(time(NULL));
- int n;
- int elemento = 0;
- int coef;
- int aux[12];
- do {
- cout << "Ingresa el tama" << char(164) << "o de las matrices: ";
- cin >> n;
- } while (n < 2 || n > 12);
- int C[12][12];
- for (int fila = 0; fila < n; fila++)
- for (int columna = 0; columna < n; columna++)
- C[fila][columna] = 0;
- int Matriz_A[12][12];
- for (int fila = 0; fila < n; fila++)
- {
- for (int columna = 0; columna < n; columna++)
- {
- Matriz_A[fila][columna] = rand() % 10 + 10;
- cout << Matriz_A[fila][columna] << " ";
- }
- cout << endl;
- }
- int Matriz_I[12][12];
- for (int fila = 0; fila < n; fila++)
- {
- for (int columna = 0; columna < n; columna++)
- {
- if (fila == columna)
- Matriz_A[fila][columna] = 1;
- else
- Matriz_A[fila][columna] = 0;
- cout << Matriz_A[fila][columna];
- }
- cout << endl;
- }
- int Matriz_B[12];
- for (int fila = 0; fila < n; fila++)
- {
- Matriz_B[fila] = rand() % 10 + 10;
- cout << Matriz_B[fila] << endl;
- }
- /*
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- for (int z = 0; z < n; z++)
- {
- C[i][j] += Matriz_A[i][z] * Matriz_I[z][j];
- }
- cout << C[i][j] << " ";
- }
- cout << endl;
- }*/
- //Iteraciones
- for (int s = 0; s<n; s++)
- {
- elemento = Matriz_A[s][s];
- for (int j = 0; j<2 * n; j++)
- Matriz_A[s][j] = Matriz_A[s][j] / elemento;
- for (int i = 0; i<n; i++)
- {
- if (i == s)
- ;
- else
- {
- coef = Matriz_A[i][s];
- for (int j = 0; j<2 * n; j++)
- aux[j] = Matriz_A[s][j] * (coef*-1);
- for (int j = 0; j<2 * n; j++)
- Matriz_A[i][j] = Matriz_A[i][j] + aux[j];
- }
- }
- }
- //Imprimir la matriz inversa
- for (int i = 0; i<n; i++)
- {
- for (int j = n; j<2 *n; j++)
- {
- cout << Matriz_A[i][j] << " ";
- if (j == n)
- cout << "n= ";
- }
- }
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement