/* 8. An equation of the form
ax^2 + bx + c = 0
is known as a quadratic equation.The values of a, b, and c in the preceding example
represent constant values. So
 
4x^2 - 17x - 15 = 0
 
represents a quadratic equation where a = 4, b = –17, and c = –15.The values of x
that satisfy a particular quadratic equation, known as the roots of the equation, can
be calculated by substituting the values of a, b, and c into the following two
formulas:
If the value of b^2–4ac, called the discriminant, is less than zero, the roots of the
equation, x1 and x2, are imaginary numbers.
Write a program to solve a quadratic equation.The program should allow
the user to enter the values for a, b, and c. If the discriminant is less than
zero, a message should be displayed that the roots are imaginary; otherwise,
the program should then proceed to calculate and display the two roots of
the equation. (Note: Be certain to make use of the squareRoot function that
you developed in this chapter.) */
 
#include <math.h>
#include <stdio.h>
 
//function to find absolute value
float absoluteValue (float d)
{
 
 
if ( d < 0 )
d = -d;
return d;
}
 
// Function to compute the square root of a number
 
float squareRoot (float d)
{
 
const float epsilon = .00001;
float guess = 1.0;
 
    while ( absoluteValue (guess * guess - d) >= epsilon )
    guess = ( d / guess + guess ) / 2.0;
     
    return guess;
}
 
// quadratic equation function
void qe (float a, float b, float c)
{
float x1, x2;
float d;
 
d = (pow (b, 2) - (4 * a * c));
     
    if (d < 0)
    printf ("x1 and x2 are imaginary numbers");
     
    x1 = (-b + squareRoot (d)) / (2 * a);
     
    printf("x1 is %f", x1);
     
    x2 = (-b - squareRoot (d)) / (2 * a);
      
    printf("x2 is %f", x2);
     
   
}

int main (void)
{
float a, b, c;
 
    printf("What is a?: \n");
    scanf("%f", &a);
       
    printf("What is b?: \n");
    scanf("%f", &b);
 
    printf("What is c?:\n");
    scanf("%f", &c);
    
     
qe (a, b, c);
   
  return 0; 
}