// Решение уравнения a*x^2 + b*x + c = 0 #include #include double a, b, c; double x1, x2; void sqroot() { if(a == 0.0) { if(b == 0.0) { if(c == 0.0) { // 0 = 0 printf("Infinite number of roots (0 = 0)\n"); } else { // c = 0 printf("No roots (c = 0)\n"); } } else { // b != 0 if (c == 0) { // b * x = 0 printf("x1 = x2 = 0 (b * x = 0)\n"); } else { // b*x + c = 0 x1 = x2 = -c / b; printf("x1 = x2 = %lf (b*x + c = 0)\n", x1); } } } else { // a != 0 if (b == 0.0) { if(c == 0.0) { // a * x^2 = 0 printf("x1 = x2 = 0 (a * x^2 = 0)\n"); } else { // a * x^2 + c = 0 x1 = (-c) / a; if(x1 > 0) { // -c/a > 0 x1 = sqrt(x1); x2 = -x1; printf ("x1 = %lf, x2 = %lf (a * x^2 + c = 0)\n", x1, x2); } else { // -c/a < 0 printf("No roots (a * x^2 + c = 0)\n"); } } } else { if(c == 0.0) { // a * x^2 + b * x = 0 printf("x1 = 0, x2 = %lf (a * x^2 + b * x = 0)\n", -b / a); } else { // a * x^2 + b* x + c = 0 double d = b*b - (a + a)*(c +c); if(d < 0.0) { printf("No roots (a * x^2 + b* x + c = 0)\n"); } else { if(d == 0) { // a != 0.0 && b x1 = x2 = -b / (a+a); printf ("x1 = x2 = %lf a * x^2 + b* x + c = 0\n", x1); } else { // d > 0 d = sqrt(d); x1 = (-b - d) / (a+a); x2 = (-b + d) / (a+a); printf ("x1 = %lf, x2 = %lf (a * x^2 + b* x + c = 0)\n", x1, x2); } } } } } return; } int main() { printf("a? "); scanf("%lf", &a); printf("b? "); scanf("%lf", &b); printf("c? "); scanf("%lf", &c); printf("%lf * x^2 + %lf * x + %lf\n", a, b, c); sqroot(); printf("test value1 = %lf\n", a * x1 * x1 + b * x1 + c); printf("test value2 = %lf\n", a * x2 * x2 + b * x2 + c); return 0; }