Grade: 15/discount: 0.8
In junior high school, we will solve the quadratic equation of a single element. Let's teach the computer how to solve it. Enter a, B, c, and the root of the quadratic equation ax 2 + bx + c = 0.
Input:
Suppose A, B, and C are all Int.
Output:
The output root must be double type, with 6 decimal places retained.
#include <stdio.h> #include <math.h> main() { int a,b,c; double xi,xii,dx; scanf("%d %d %d",&a,&b,&c); dx=b*b-4*a*c; if (a==0 && b==0) printf("Input error!\n"); else if (a==0) { if (c==0) printf("x=0.000000\n"); else printf("x=%.6f\n",-1.0*c/b); } else if (dx==0) { if (b==0) printf("x1=x2=0.000000"); else printf("x1=x2=%.6f\n",-1.0*b/2/a); } else if (dx>0) { xi=(-b+sqrt(dx))/2/a; xii=(-b-sqrt(dx))/2/a; /*if (xi<xii) {dx=xi;xi=xii;xii=dx;}*/ printf("x1=%.6f\nx2=%.6f\n",xi,xii); } else if (b==0) printf("x1=%.6fi\nx2=%.6fi\n",sqrt(-dx)/2/a,-sqrt(-dx)/2/a); else printf("x1=%.6f+%.6fi\nx2=%.6f-%.6fi\n",-1.0*b/2/a,sqrt(-dx)/2/a,-1.0*b/a/2,sqrt(-dx)/a/2); }