Advertisement
mohamed_wagdy12

Untitled

Apr 26th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. 0.91 KB
  2. /*
  3. University : HTI
  4. CodeName : Write a program to get the inverse of matrix[2][2]
  5. SubjectName : Programming Structure
  6. SubjectCode : csc121
  7. Group : https://www.facebook.com/groups/1421186571334814
  8. event : Ready to final
  9. */
  10.  
  11. #include "stdafx.h"
  12. #include "iostream"
  13.  
  14. using namespace std;
  15.  
  16. int main(void)
  17. {
  18.  
  19. float x[2][2], y[2][2], k;
  20.  
  21. for(int i = 0; i < 2; i++)
  22. {
  23. for(int n = 0; n < 2; n++)
  24. {
  25. cout << "X[" << (i+1) << "][" << (n+1) << "]= ";
  26. cin >> x[i][n];
  27. }
  28. }
  29.  
  30. k = x[0][0]*x[1][1] - x[0][1]*x[1][0];
  31.  
  32. if(k == 0)
  33. {
  34. cout << "There is no inverse for this matrix!";
  35. } else {
  36. y[0][0] = x[1][1] / k;
  37. y[0][1] = - x[0][1] / k;
  38. y[1][0] = - x[1][0] / k;
  39. y[1][1] = x[0][0] / k;
  40.  
  41. // print inverse matrix
  42. for(int i = 0; i < 2; i++)
  43. {
  44. for(int n = 0; n < 2; n++)
  45. {
  46. cout << " " << y[i][n] << " ";
  47. }
  48. cout << endl;
  49. }
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement