Halla las raíces reales de ax² + bx + c = 0. El discriminante es d = b² − 4ac: si d > 0 hay dos raíces (−b ± √d) / 2a; si d = 0, una; si d < 0, ninguna real. roots(a, b, c) muestra una línea: cuántas raíces hay y luego las raíces (2 decimales). Por ejemplo, x² − 5x + 6 = 0 muestra 2 3.00 2.00.
2 3.00 2.00 2 0.28 -1.78 1 -1.00 0
#include <stdio.h>
#include <math.h>
void roots(double a, double b, double c) {
double d = 0;
// tu código aquí: calcula el discriminante d
if (d > 0) {
double x1 = 0, x2 = 0;
// tu código aquí: usa la fórmula para calcular x1 (con +) y x2 (con −)
printf("2 %.2f %.2f\n", x1, x2);
} else if (d == 0) {
printf("1 %.2f\n", -b / (2 * a));
} else {
printf("0\n");
}
}
int main(void) {
roots(1, -5, 6);
roots(2, 3, -1);
roots(1, 2, 1);
roots(1, 1, 1);
return 0;
}
Ejecutar prueba los ejemplos. Cuando salgan bien, Enviar.