// ================================================================== // Program : roots_poly.c // Date : October 2020 // Author: Jean-Michel RICHER // Email : jean-michel.richer@univ-angers.fr // ================================================================== // Description : calcul des racines de l'équation ax^2 + bx + c = 0 // ================================================================== #include #include #include float a = 1.0; float b = 2.0; float c = 1.0; float delta, x1, x2; /** * Fonction principale */ int main(int argc, char *argv[]) { if (argc > 1) a = atof( argv[1] ); if (argc > 2) b = atof( argv[2] ); if (argc > 3) c = atof( argv[3] ); delta = b*b - 4*a*c; if (delta < 0.0) { printf("pas de solution dans R\n"); } else { x1 = (-b + sqrt(delta))/(2*a); x2 = (-b - sqrt(delta))/(2*a); printf("racines %g et %g\n", x1, x2); printf("(x + %g)*(x + %g) = %g x^2 + %g x + %g\n", -x1, -x2, a, b, c); } return EXIT_SUCCESS; }