Created
January 31, 2012 22:36
-
-
Save SebastianTroc/1713504 to your computer and use it in GitHub Desktop.
Matrix determinants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main() | |
| { | |
| /* | |
| * Przykladowa macierz 3x3: | |
| * 0 1 2 | |
| * 0 [1][2][3] | |
| * 1 [3][2][5] | |
| * 2 [0][4][1] | |
| * | |
| */ | |
| int aMacierz[3][3]; | |
| //Wprowadzanie danych | |
| for (short i=0; i<=2; i++) { | |
| for (short j=0; j<=2; j++) { | |
| cout << "Podaj wartosc [" << i << "][" << j << "] = "; | |
| cin >> aMacierz[i][j]; | |
| } | |
| } | |
| //Wyswietlenie macierzy | |
| cout << "Macierz ma postac:" << endl; | |
| for (short int i=0; i<=2; i++) { | |
| cout << "\t"; | |
| for (short j=0; j<=2; j++) { | |
| cout << "[" << aMacierz[i][j] << "] "; | |
| } | |
| cout << endl; | |
| } | |
| //Liczenie skosow | |
| int nSkosDodatni = aMacierz[0][0] * aMacierz[1][1] * aMacierz[2][2] + | |
| aMacierz[1][0] * aMacierz[2][1] * aMacierz[0][2] + | |
| aMacierz[2][0] * aMacierz[0][1] * aMacierz[1][2]; | |
| int nSkosUjemny = aMacierz[0][2] * aMacierz[1][1] * aMacierz[2][0] + | |
| aMacierz[1][2] * aMacierz[2][1] * aMacierz[0][0] + | |
| aMacierz[2][2] * aMacierz[0][1] * aMacierz[1][1]; | |
| //Obliczenie wyznacznika | |
| unsigned long nDet = nSkosDodatni - nSkosUjemny; | |
| //Wyswietlenie wyniku | |
| cout << "Wyznacznik tej macierzy wynosi " << nDet << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment