Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- cout << "This is a programme about solving 2x2 system with 2 variables (x and y)." << endl;
- cout << "Give me the factors before x, y and the constant factor of 1st equation." << endl;
- double a1, b1, c1;
- double a2, b2, c2;
- cin >> a1;
- cin >> b1;
- cin >> c1;
- cout << "Now, do the same for the 2nd equation." << endl << endl;
- cin >> a2;
- cin >> b2;
- cin >> c2;
- // Για το πώς θα γραφεί η 1η εξίσωση
- if (a1>=0) {
- if(b1>=0){
- cout << a1 << "x +" << b1 << "y = " << c1 << endl;
- }
- else{
- cout << a1 << "x" << b1 << "y = " << c1 << endl;
- }
- }
- else{
- if(b1>=0){
- cout << a1 << "x +" << b1 << "y = " << c1 << endl;
- }
- else{
- cout << a1 << "x" << b1 << "y = " << c1 << endl;
- }
- }
- // Για το πως θα γραφτεί η 2η εξίσωση
- if (a2>=0) {
- if(b2>=0){
- cout << a2 << "x +" << b2 << "y = " << c2 << endl;
- }
- else{
- cout << a2 << "x" << b2 << "y = " << c2 << endl;
- }
- }
- else{
- if(b2>=0){
- cout << a2 << "x +" << b2 << "y = " << c2 << endl;
- }
- else{
- cout << a2 << "x" << b2 << "y = " << c2 << endl;
- }
- }
- float Dx = c1*b2 - c2*b1;
- float Dy = a1*c2 - a2*c1;
- float D = a1*b2 - a2*b1;
- if (D==0){
- if (c1/c2==a1/a2 && c1/c2==b1/b2){
- cout << "This system has infinite solutions: ( x, (" << c1 << "-" << a1 << "x" << "/" << b1 << ") )" << endl;
- }
- else{
- cout << "No solutions. Impossible system." << endl;
- }
- }
- else{
- cout << "Solution: " << endl;
- cout << "x = " << Dx/D << endl;
- cout << "y = " << Dy/D << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement