From 69de8ecfb2df52a6a4ae9d75f6a018ae380cca05 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 25 Oct 2025 18:07:05 +0300 Subject: feat(Week04): Add exercises and solutions --- Week04/Exercise04.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Week04/Exercise04.cpp (limited to 'Week04/Exercise04.cpp') diff --git a/Week04/Exercise04.cpp b/Week04/Exercise04.cpp new file mode 100644 index 0000000..a64f1f2 --- /dev/null +++ b/Week04/Exercise04.cpp @@ -0,0 +1,25 @@ +#include +#include + +int main() { + float a, b, c; + std::cin >> a >> b >> c; + + float determinant = b * b - 4.0 * a * c; + // Тези сравнения колко са коректни така? + // Могат ли да се породят проблеми заради точност? + if (determinant < 0.0) { + std::cout << "No real roots"; + } + else if (determinant == 0.0) { + float x = -b / (2 * a); + std::cout << x; + } + else { + float x1 = (-b + sqrt(determinant)) / (2 * a); + float x2 = (-b - sqrt(determinant)) / (2 * a); + std::cout << x1 << ' ' << x2; + } + + return 0; +} -- cgit v1.3.1-23-gd82d