#include #include #include // Solve a*x^2 + b*x + c = 0 and return the two roots. // For the equation x^2 - 3*x + 2 = 0 the roots are 2 and 1. std::tuple solve_quadratic(double a, double b, double c) { double discriminant = b * b - 4.0 * a * c; double sqrt_disc = std::sqrt(discriminant); double root1 = (-b + sqrt_disc) / (2.0 * a); double root2 = (-b - sqrt_disc) / (2.0 * a); return {root1, root2}; } int main() { // Structured binding decomposes the tuple into two distinct names. auto [root1, root2] = solve_quadratic(1.0, -3.0, 2.0); // Print exactly "roots: 2, 1". std::println("roots: {}, {}", root1, root2); return 0; }