CS 2073, Fall 2005
 Program 2
 Roots of a Quadratic Equation
    Week 2: Aug 29-Sep 2
 Due (on time): 2005-09-09  23:59:59
 Due (late):        2005-09-12  23:59:59

Program 2 must be emailed to: nrwagner@cs.utsa.edu
following directions for: running and submitting a C program, with deadlines:
  • 2005-09-09  23:59:59 (that's Friday, 9 September 2005, 11:59:59 pm) for full credit.
  • 2005-09-12  23:59:59 (that's Monday, 12 September 2005, 11:59:59 pm) for 75% credit.


Introduction: For this program you are to find the roots of a quadratic equation. Specifically, start with an equation: a*x2 + b*x + c = 0 , for specific doubles a, b, and c.

Then calculate and print the values of the roots, r1 and r2.


Details about what to do:
  1. Use scanf to read values for double variables a, b, and c, which are assumed to be the coefficients of a quadratic equation.
  2. Print the input numbers in the form of a quadratic equation, using the form shown in the example section below.
  3. If a is equal to zero, print a message that this is linear equation. In case b is not zero, there is a single root, and if b does equal zero, there is no root. Print the value of this root or print that there is no root.
  4. Otherwise, calculate the discriminant d given by d = b2 - 4*a*c
  5. If the discriminant is greater than zero, then there are two real roots. Print a message that says this, use the quadratic formula to calculate their values, r1 and r2, and print these two values.
  6. In case the discriminant is equal to zero, there is a single repeated real root. Print a message that says this, use the quadratic formula to calculate the value, and print this value.
  7. If the discriminant is less than zero, then there two imaginary roots. Print a message that there are two imaginary roots and then print the real and imaginary part of each root. (The real part of both roots is the same: -b/(2*a), while the imaginary parts are sqrt(-d)/(2*a) and -sqrt(-d)/(2*a). Notice that we have d < 0, so -d > 0, and it makes sense to take the square root of -d.)


Sample input and output: You may use a separate run for each input triple of numbers. Below in bold are the three numbers that you enter for each separate run. Everything else is what your program should output. You should try each of these 8 sets of inputs and your answers should be the same. For full credit, your output should look exactly the same as the output shown. (However, don't worry about the number of spaces before an output number.)


What you should email: Refer to the submissions directions and to deadlines at the top of this page. The text file that you submit should first have Your Name, the Course Number, and the Program Number. The rest of the file should have the following in it, in the order below, and clearly labeled, including at the beginning the appropriate item letters: a, b, c, etc.

 Contents of email submission for Program 2:

Last Name, First Name; Course Number; Program Number.

  1. C source for your program, quadratic.c. (Or whatever you wish to name it.)
  2. Results of a run or runs of the program, including at least all the 8 sets of data above.


Revision date: 2005-09-03. (Please use ISO 8601, the International Standard.)