Created
December 2, 2016 22:08
-
-
Save Mati365/b09ae3dcdf6cf917c1bb3f75ab4eed6e to your computer and use it in GitHub Desktop.
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> | |
#include <math.h> | |
#include <iomanip> | |
using namespace std; | |
/** wyznacznik arraya */ | |
float fckd(float jpdl[2][2]) { | |
return jpdl[0][0] * jpdl[1][1] - jpdl[0][1] * jpdl[1][0]; | |
} | |
int main() { | |
cout | |
<< "Uklad rownan: " << endl | |
<< "ax + by = e" << endl | |
<< "cx + dy = f" << endl; | |
float a = 3, b = -2, e = 2, c = -1, d = 4, f = 1; | |
cout << "Podaj a: "; cin >> a; | |
cout << "Podaj b: "; cin >> b; | |
cout << "Podaj e: "; cin >> e; | |
cout << "Podaj c: "; cin >> c; | |
cout << "Podaj d: "; cin >> d; | |
cout << "Podaj f: "; cin >> f; | |
cout << "Fantastycznie! Oto wynik:" << endl; | |
/** | |
* | |
* A = [ a b ] | |
* [ c d ] | |
* | |
* X = [ x ] | |
* [ y ] | |
* | |
* B = [ e ] | |
* [ f ] | |
* | |
* x = (detAx / detA) | |
* y = (detAy / detA) | |
*/ | |
float A[2][2] = { | |
{ a, b }, | |
{ c, d } | |
}; | |
float B[2] = { | |
e, | |
f | |
}; | |
float Ax[2][2] = { | |
{ B[0], A[0][1] }, | |
{ B[1], A[1][1] } | |
}; | |
float Ay[2][2] = { | |
{ A[0][0], B[0] }, | |
{ A[1][0], B[1] } | |
}; | |
/** Wspollczynniki */ | |
float detA = fckd(A) | |
, detAx = fckd(Ax) | |
, detAy = fckd(Ay); | |
if(detA) { | |
cout | |
<< "x = " << detAx / detA << endl | |
<< "y = " << detAy / detA << endl; | |
} else { | |
if(!detAx && !detAy) cout << "Uklad ma nieskonczenie wiele rozwiazan" << endl; | |
else cout << "Sprzeczny" << endl; | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment