Advertisement
spamspam252

Untitled

Feb 28th, 2015
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. float data(float a[3][5], int n)
  2. {
  3. // n = 3
  4. float x = 1, y = 1, z = 1, f, v = 1,m = 1,o = 1;
  5. int k = 2 , l = 0;
  6. float B[3][5];
  7.  
  8. for (int i = 0; i < n; i++)
  9. {
  10. for (int j = 0; j < n; j++)
  11. B[i][j] = a[i][j];
  12. }
  13.  
  14. for (int i = 0; i < n; i++)
  15. {
  16. B[i][3] = a[i][0];
  17. B[i][4] = a[i][1];
  18. }
  19.  
  20.  
  21. if (n == 2)
  22. {
  23. f = (a[0][0] * a[1][1]) - (a[0][1] * a[1][0]);
  24. }
  25. else
  26. {
  27. for (int j = 0; j < n; j++)
  28. {
  29.  
  30. x *= B[j][j];
  31. y *= B[j][j + 1];
  32. z *= B[j][j + 2];
  33.  
  34. v *= B[j][k];
  35. m *= B[j][k + 1];
  36. o *= B[j][k + 2];
  37. k -= 1;
  38.  
  39. }
  40.  
  41. f = x + y + z - v - m - o;
  42. }
  43.  
  44. return f;
  45. }
  46.  
  47. void hpt2()
  48. {
  49. float a[3][5]; float b[3][3]; float c[3][1]; float f;
  50. float a1[3][5]; float a2[3][5]; float a3[3][5];
  51. float x, y, z;
  52. cout << "Hay nhap gia tri nhu duoi day: " << endl;
  53. cout << "a[0][0]x + a[0][1]y + a[0][2] = c0" << endl;
  54. cout << "a[1][0]x + a[1][1]y + a[1][2] = c1" << endl;
  55. cout << "a[2][0]x + a[2][1]y + a[2][2] = c2" << endl;
  56. cout << endl;
  57.  
  58. for (int i = 0; i <= 2; i++)
  59. for (int j = 0; j <= 2; j++)
  60. {
  61. cout << "Hay nhap a[" << i << "]" << "[" << j << "]: ";
  62. cin >> a[i][j];
  63. }
  64.  
  65. for (int i = 0; i <= 2; i++)
  66. {
  67. cout << "Hay nhap c" << i << ": ";
  68. cin >> c[i][0];
  69. }
  70.  
  71. f = data(a, 3);
  72.  
  73. if (f == 0)
  74. cout << "He pt vo nghiem" << endl;
  75. else
  76. {
  77. for (int i = 0; i <= 2; i++)
  78. for (int j = 0; j <= 2; j++)
  79. {
  80. a1[i][j] = a[i][j];
  81. a2[i][j] = a[i][j];
  82. a3[i][j] = a[i][j];
  83. }
  84.  
  85.  
  86. for (int i = 0; i <= 2; i++)
  87. {
  88. a1[i][0] = c[i][0];
  89. a2[i][1] = c[i][0];
  90. a3[i][2] = c[i][0];
  91. }
  92.  
  93. x = data(a1, 3) / f;
  94. y = data(a2, 3) / f;
  95. z = data(a3, 3) / f;
  96.  
  97. cout << "He phuong trinh co nghiem la: " << endl;
  98. cout << "x = " << x << endl;
  99. cout << "y = " << y << endl;
  100. cout << "z = " << z << endl;
  101. }
  102. }
  103.  
  104. void hpt1()
  105. {
  106. float f, x , y;
  107. float a[3][5]; float b[2][2]; float c[2][1];
  108. float a1[3][5]; float a2[3][5];
  109. cout << "Hay nhap gia tri nhu duoi day: " << endl;
  110. cout << "a[0][0]x + a[0][1]y = c0" << endl;
  111. cout << "a[1][0]x + a[1][1]y = c1" << endl;
  112. cout << endl;
  113.  
  114. for (int i = 0; i <= 1; i++)
  115. {
  116.  
  117. for (int j = 0; j <= 1; j++)
  118. {
  119. cout << "Hay nhap a[" << i << "]" << "[" << j << "]: ";
  120. cin >> a[i][j];
  121. }
  122.  
  123. }
  124. for (int i = 0; i <= 1; i++)
  125. {
  126. cout << "Hay nhap c" << i << ": ";
  127. cin >> c[i][0];
  128. }
  129.  
  130. f = data(a, 2);
  131.  
  132. if (f == 0)
  133. cout << "He pt vo nghiem" << endl;
  134. else
  135. {
  136. for (int i = 0; i <= 1; i++)
  137. for (int j = 0; j <= 1; j++)
  138. {
  139. a1[i][j] = a[i][j];
  140. a2[i][j] = a[i][j];
  141. }
  142.  
  143.  
  144. for (int i = 0; i <= 1; i++)
  145. {
  146. a1[i][0] = c[i][0];
  147. a2[i][1] = c[i][0];
  148. }
  149.  
  150. x = data(a1, 2) / f;
  151. y = data(a2, 2) / f;
  152.  
  153. cout << "He phuong trinh co nghiem la: " << endl;
  154. cout << "x = " << x << endl;
  155. cout << "y = " << y << endl;
  156. }
  157.  
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement