Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 0.91 KB
- /*
- University : HTI
- CodeName : Write a program to get the inverse of matrix[2][2]
- SubjectName : Programming Structure
- SubjectCode : csc121
- Group : https://www.facebook.com/groups/1421186571334814
- event : Ready to final
- */
- #include "stdafx.h"
- #include "iostream"
- using namespace std;
- int main(void)
- {
- float x[2][2], y[2][2], k;
- for(int i = 0; i < 2; i++)
- {
- for(int n = 0; n < 2; n++)
- {
- cout << "X[" << (i+1) << "][" << (n+1) << "]= ";
- cin >> x[i][n];
- }
- }
- k = x[0][0]*x[1][1] - x[0][1]*x[1][0];
- if(k == 0)
- {
- cout << "There is no inverse for this matrix!";
- } else {
- y[0][0] = x[1][1] / k;
- y[0][1] = - x[0][1] / k;
- y[1][0] = - x[1][0] / k;
- y[1][1] = x[0][0] / k;
- // print inverse matrix
- for(int i = 0; i < 2; i++)
- {
- for(int n = 0; n < 2; n++)
- {
- cout << " " << y[i][n] << " ";
- }
- cout << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement