Question: Write a C program write a function in ANSI C that compute both roots of a quadratic equation int solve(double a, double b, double c,

Write a C program

write a function in ANSI C that compute both roots of a quadratic equation

int solve(double a, double b, double c, double *root1, double *root2) that solve ax^2+bx+c=0, using solution (-b+ - sqrt(b^2-4ac)/2a

function solve should return either 2(two root were found), 1(one root was found) , 0(no roots were found). need not check for overflow. If one one root is found, it should be returned in root1. you may assume that a is not 0.

write a testing function tester(double a, double b, double c, char *msg)

that calls your solve() function and prints out the result along with the ms passed as arguent. tester should only printout the correct number of roots.

write a main function that tests your code above. main function should at least call

tester(1.0,0.0,4.0,"no solution");

tester(1.0,0.0,-4.0,"two solution");

tester(1.0,0.0,0.0,"one solution");

note: the sqrt() function is defned in the math library (include file and library -lm

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!