Puzzle E22

Math to C

Complete the following program so that it evaluates this formula:

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

/* Puzzle E22 -- math to C, Yet Again*/
 
int main()
{
  double a = 1.4, b = 4.2, c = -2.4;
  double discrim, result;
  
  discrim =   ;  /* Complete this statement */
  
  if   (  )
  {
    result =    ;  /* Complete this statement */
  
    printf("result: %f\n", result ); 
  }
  else
  {
    printf("No real number solution\n" );   
  }
  return 0;
}

Use double sqrt( double ) from the standard math library for the square root. But it requires an argument >= 0.0 to work. Use a variable to hold and test an intermediate value.

Of course, to test your program you would use several values for a, b, and c that make it clear that the result is correct or not.



Previous Page        Answer         Next Page         Home