labprog3-2010

# labprog3-2010 - appropriate statements to your program so...

This preview shows page 1. Sign up to view the full content.

Swinburne University of Technology Faculty of Engineering and Industrial Sciences HES1300 Laboratory assignment 3: Write a program which accepts as data the three coefficients A, B, C which define a quadratic equation 0 2 = + + C Bx Ax . The program should then compute and print the value of the discriminant (B 2 –4AC). Your program should read A, B and C from console (use scanf) and compute both solutions of the quadratic equation and display the answers. The program should be carefully checked and tested, using values of the coefficients which ensure that the discriminant is not negative. To compute a square root in C, use the sqrt function from C math library. After finishing the above part and in order to improve your program, firstly, add the
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: appropriate statements to your program so that if the discriminant is negative, the program will print out a message saying something to the effect that “the equation has no real roots”. Secondly, when you have tested the above, add statements so that your program will never attempt to divide by a zero or near zero number. In this case, the program should print a message to the effect that the quadratic function has degenerated to a first order polynomial. Your program may look like: #include <stdio.h> #include <math.h> int main() { float A,B,C, discr; … return(0); }...
View Full Document

## This note was uploaded on 09/29/2010 for the course C++ c taught by Professor Lauren during the Three '10 term at Swinburne.

Ask a homework question - tutors are online