Assignment 6
1. Write a program to compute the roots of a quadratic equation
ax
2
+ bx + c =
0, where a, b, and c are real numbers. Structure your program as described
below.
A. The input file is named
input_equations.txt which contains the three
coefficients of an equation in each line
as below:
1.0 3.0 2.0
1 0 4.84
1 0 1
You may create more inputs if you need.
Open
pico input_equations.txt
1.0
3.0
2.0
1
0
4.84
1
0
1
B. Write a function
compute_roots that has five parameters:
a : Coefficient of x2
b : Coefficient of x
c : constant term
*root1 : pointer to a double type variable
*root2 : pointer to a double type variable
The function updates the memory locations pointed to by root1 and root2
with the two roots of the quadratic equation, if they have
realvalued roots. If
the roots are complex, then the memory locations are left unchanged. The
function returns a value 1 if the roots are realvalued, otherwise returns 0.
C. Write the main function which reads the equations from the input file, one
at a time, computes the roots using the function compute_roots. The output
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 Grubbs
 Computer Programming

Click to edit the document details