Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. //void MatrizIndentidad()
  7. //{
  8. //
  9. // int Matriz_I[12][12];
  10. //
  11. // for (int fila = 0; fila < 12; fila++)
  12. // {
  13. // for (int columna = 0; columna < 12; columna++)
  14. // {
  15. // if (fila == columna)
  16. // Matriz_I[fila][columna] = 1;
  17. // else
  18. // Matriz_I[fila][columna] = 0;
  19. //
  20. // cout << Matriz_I[fila][columna];
  21. // }
  22. // cout << endl;
  23. // }
  24. //}
  25.  
  26. //void MatrizA( int m[][12], int _n, int _n2)
  27. //{
  28. //
  29. // srand(time(NULL));
  30. // int Matriz_A[12][12];
  31. //
  32. // for (int fila = 0; fila < _n; fila++)
  33. // {
  34. // for (int columna = 0; columna < 12; columna++)
  35. // {
  36. // Matriz_A[fila][columna] = rand() % 10 + 1;
  37. //
  38. // cout << Matriz_A[fila][columna] << " ";
  39. // }
  40. //
  41. // cout << endl;
  42. // }
  43. //
  44. //}
  45.  
  46. //void MatrizB()
  47. //{
  48. // srand(time(NULL));
  49. // int Matriz_B[12];
  50. //
  51. // for (int fila = 0; fila < 12; fila++)
  52. // {
  53. // Matriz_B[fila] = rand() % 50 + 10;
  54. //
  55. // cout << Matriz_B[fila] << endl;
  56. // }
  57. //}
  58.  
  59. void main()
  60. {
  61. srand(time(NULL));
  62.  
  63.  
  64.  
  65. int n;
  66. int elemento = 0;
  67. int coef;
  68. int aux[12];
  69. do {
  70. cout << "Ingresa el tama" << char(164) << "o de las matrices: ";
  71. cin >> n;
  72.  
  73. } while (n < 2 || n > 12);
  74.  
  75. int C[12][12];
  76. for (int fila = 0; fila < n; fila++)
  77. for (int columna = 0; columna < n; columna++)
  78. C[fila][columna] = 0;
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. int Matriz_A[12][12];
  92. for (int fila = 0; fila < n; fila++)
  93. {
  94. for (int columna = 0; columna < n; columna++)
  95. {
  96. Matriz_A[fila][columna] = rand() % 10 + 10;
  97.  
  98. cout << Matriz_A[fila][columna] << " ";
  99. }
  100.  
  101. cout << endl;
  102. }
  103.  
  104.  
  105. int Matriz_I[12][12];
  106. for (int fila = 0; fila < n; fila++)
  107. {
  108. for (int columna = 0; columna < n; columna++)
  109. {
  110. if (fila == columna)
  111. Matriz_A[fila][columna] = 1;
  112. else
  113. Matriz_A[fila][columna] = 0;
  114.  
  115. cout << Matriz_A[fila][columna];
  116. }
  117. cout << endl;
  118. }
  119.  
  120.  
  121.  
  122.  
  123.  
  124. int Matriz_B[12];
  125. for (int fila = 0; fila < n; fila++)
  126. {
  127. Matriz_B[fila] = rand() % 10 + 10;
  128.  
  129. cout << Matriz_B[fila] << endl;
  130. }
  131.  
  132.  
  133. /*
  134. for (int i = 0; i < n; i++)
  135. {
  136. for (int j = 0; j < n; j++)
  137. {
  138. for (int z = 0; z < n; z++)
  139. {
  140. C[i][j] += Matriz_A[i][z] * Matriz_I[z][j];
  141.  
  142. }
  143. cout << C[i][j] << " ";
  144. }
  145. cout << endl;
  146. }*/
  147.  
  148.  
  149.  
  150. //Iteraciones
  151. for (int s = 0; s<n; s++)
  152. {
  153. elemento = Matriz_A[s][s];
  154. for (int j = 0; j<2 * n; j++)
  155. Matriz_A[s][j] = Matriz_A[s][j] / elemento;
  156. for (int i = 0; i<n; i++)
  157. {
  158. if (i == s)
  159. ;
  160. else
  161. {
  162. coef = Matriz_A[i][s];
  163. for (int j = 0; j<2 * n; j++)
  164. aux[j] = Matriz_A[s][j] * (coef*-1);
  165. for (int j = 0; j<2 * n; j++)
  166. Matriz_A[i][j] = Matriz_A[i][j] + aux[j];
  167. }
  168. }
  169. }
  170.  
  171.  
  172. //Imprimir la matriz inversa
  173. for (int i = 0; i<n; i++)
  174. {
  175. for (int j = n; j<2 *n; j++)
  176. {
  177. cout << Matriz_A[i][j] << " ";
  178. if (j == n)
  179. cout << "n= ";
  180. }
  181. }
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188. _getch();
  189.  
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement