Encontre as raízes reais de ax² + bx + c = 0. O delta é d = b² − 4ac: se d > 0 há duas raízes (−b ± √d) / 2a, se d = 0 há uma, se d < 0 não há raiz real. roots(a, b, c) mostra uma linha: quantas raízes e depois as raízes (2 casas decimais). Por exemplo, x² − 5x + 6 = 0 mostra 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;
// seu código aqui: calcule o delta d
if (d > 0) {
double x1 = 0, x2 = 0;
// seu código aqui: use a fórmula para calcular x1 (com +) e x2 (com −)
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;
}
Executar testa os exemplos. Quando parecerem certos, Enviar.