Bifalgorithm post · Computer science one · Computing Quadratic Roots
How can a C program compute the roots of a quadratic equation?
How can a C program compute the roots of a quadratic equation? (Computer science one · Computing Quadratic Roots) — "Some programs require the user to enter mu…
Ideas in this flowchart
- A program prompts for quadratic coefficients and computes the roots
- The program uses a main() function as its basic structure
- The prompt-input process is repeated for multiple inputs
- Prompt for and read coefficient a
- Prompt for and read coefficient b
- Prompt for and read coefficient c
- The program declares variables for the coefficients and roots
- Three double variables store a, b, and c
- Two double variables store root1 and root2
- The roots are computed with the quadratic formula
- The formula must be adapted carefully to preserve the order of operations
- The computation uses the standard math library square root function
- root1 = (-b + sqrt(b*b - 4*a*c)) / (2*a)
- root2 = (-b - sqrt(b*b - 4*a*c)) / (2*a)
- The program prints the computed output using printf()
- The complete program is available in the Code Sample