COMPUTING THE DETERMINANT OF THE MATRIX



#include "stdafx.h"
#include "iostream"
#define N 4
using namespace std;
void main(){
       int i, j, k;
       double A[N + 1][N + 1];
       cout << "Input variables for matrix A" << endl;
       cout << "a11=" << endl;
       cin >> A[1][1];
       cout << "a12=" << endl;
       cin >> A[1][2];
       cout << "a13=" << endl;
       cin >> A[1][3];
       cout << "a14=" << endl;
       cin >> A[1][4];
       cout << "a21=" << endl;
       cin >> A[2][1];
       cout << "a22=" << endl;
       cin >> A[2][2];
       cout << "a23=" << endl;
       cin >> A[2][3];
       cout << "a24=" << endl;
       cin >> A[2][4];
       cout << "a31=" << endl;
       cin >> A[3][1];
       cout << "a32=" << endl;
       cin >> A[3][2];
       cout << "a33=" << endl;
       cin >> A[3][3];
       cout << "a34=" << endl;
       cin >> A[3][4];
       cout << "a41=" << endl;
       cin >> A[4][1];
       cout << "a42=" << endl;
       cin >> A[4][2];
       cout << "a43=" << endl;
       cin >> A[4][3];
       cout << "a44=" << endl;
       cin >> A[4][4];
       for (i = 1; i <= N; i++)
       {
             for (j = 1; j <= N; j++)
             {
                    cout << A[i][j] << " ";
             }
             cout << endl;
       }
       double Product, m;
       for (k = 1; k <= N - 1; k++)
             for (i = k + 1; i <= N; i++){
                    m = A[i][k] / A[k][k];
                    for (j = 1; j <= N; j++)
                           for (j = 1; j <= N; j++)
                                  A[i][j] -= m*A[k][j];
             }
       cout << endl << "matrix U: " << endl;
       for (i = 1; i <= N; i++)
       {
             for (j = 1; j <= N; j++)
                    cout << A[i][j] << " ";
             cout << endl;
       }
       Product = 1;
       for (i = 1; i <= N; i++)
             Product *= A[i][i];
       cout << endl << "det(A)=" << Product << endl;
       system("pause");
}


Share on Google Plus