/*--------------------------------------------------------------------*/
		    	
/*--------------------------------------------------------------------*/
/*  Problem chapter4_27                                               */
/*                                                                    */
/*  This program determines the roots of a quadratic equation.        */

#include <stdio.h>
#include <math.h>

int main(void)
{
   /*  Declare variables.  */
   double a, b, c, discriminant, root1, root2;
    
   /*  Prompt user for equation.  */
   printf("Enter a,b,c for equation ax^2 + bx + c: ");
   scanf("%lf %lf %lf",&a,&b,&c);
   printf("Equation is: %fx^2 + %fx + %f = y\n",a,b,c);

   /*  Are the roots complex?  */
   discriminant = b*b - 4*a*c;
   if (discriminant < 0.0)
   {
	root1 = -b/(2*a);
	root2 = sqrt(abs(discriminant))/(2*a);
      printf("Roots are: x1= %f + j%f, x2 = %f -j%f\n",
             root1 root2,root1,root2);
    }
   else
   {
	root1 = (-b + sqrt(discriminant)) / (2*a);
	root2 = (-b - sqrt(discriminant)) / (2*a);
	printf("Roots are: x1=%f, x2=%f\n",root1,root2);
   }

   /*  Exit program.  */
   return 0;
}
/*--------------------------------------------------------------------*/
