Skip to content

Instantly share code, notes, and snippets.

@Mati365
Last active December 2, 2016 21:25
Show Gist options
  • Save Mati365/5c7ee6d66bfa8998bd423ed4e33c9439 to your computer and use it in GitHub Desktop.
Save Mati365/5c7ee6d66bfa8998bd423ed4e33c9439 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <math.h>
using std::cout;
using std::cin;
using std::endl;
int main() {
float a, b, c;
cout
<< "Program rozwiazuje rownanie kwadratowe w postaci: " << std::endl
<< "ax^2 + bx + c = 0" << endl
<< "Podaj a: "; cin >> a;
cout << "Podaj b: "; cin >> b;
cout << "Podaj c: "; cin >> c;
if(!b && !c && !a) {
cout << "Nieskonczenie wiele rozwiazan" << endl;
} else if(!a) {
cout << "Rozwiazanie funkcji liniowej to: " << -c / b << endl;
} else {
float delta = pow(b, 2) - 4 * a * c;
if(delta < 0) {
delta = -delta;
cout
<< "Nie posiada pierwiastkow rzeczywistych ale ma zespolone" << endl
<< "x0: (" << -b << "-" << sqrt(delta) << "i) / (" << 2 * a << ")" << endl
<< "x1: (" << -b << "+" << sqrt(delta) << "i) / (" << 2 * a << ")" << endl;
} else if(delta > 0) {
cout
<< "Rozwiazanie: " << endl
<< "x0: " << (-b - sqrt(delta)) / (2 * a) << endl
<< "x1: " << (-b + sqrt(delta)) / (2 * a) << endl;
} else {
cout << "Rozwizanie x: " << (-b) / (2 * a) << endl;
}
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment