From 3e7e6a7200e77ce95136f3924b3cb7453d246fa4 Mon Sep 17 00:00:00 2001 From: w65567 Date: Tue, 10 May 2022 13:59:45 +0200 Subject: [PATCH] 5A_4 --- ConsoleApplication1/ConsoleApplication1.cpp | 27 ++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/ConsoleApplication1/ConsoleApplication1.cpp b/ConsoleApplication1/ConsoleApplication1.cpp index 4e4065f..dd53786 100644 --- a/ConsoleApplication1/ConsoleApplication1.cpp +++ b/ConsoleApplication1/ConsoleApplication1.cpp @@ -1,8 +1,29 @@ -#include +#include +#include using namespace std; int main() { - cout << "Hello World!" << endl; -} + cout << setprecision(2); + float a, b, c; + cout << "Podaj a: ", cin >> a; + cout << "Podaj b: ", cin >> b; + cout << "Podaj c: ", cin >> c; + + cout << "Rownanie: " << a << "x^2 + " << b << "x + " << c << " = 0" << endl; + + float delta = (b * b) - (4 * a * c); + if (delta < 0) cout << "Brak pierwiastkow" << endl; + else if (delta == 0) { + float x = -b / (2 * a); + cout << "1 pierwiastek: x = " << x << endl; + } + else { + float x1, x2; + float sq = sqrt(delta); + x1 = (-b - sq) / (2 * a); + x2 = (-b + sq) / (2 * a); + cout << "2 pierwiastki: x1 = " << x1 << ", x2 = " << x2 << endl; + } +} \ No newline at end of file