Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a) Design and code a C function named roots that calculates the roots of a quadratic equation. Your function receives three doubles that hold

a) Design and code a C function named roots that calculates the roots of a quadratic equation. Your function receives three doubles that hold the coefficients of the quadratic equation and returns through two other double parameters the real roots of the equation. The function returns the number of real roots found as the return value of the function itself. The header for your function looks something like: int roots(double a, double b, double c, double *r1, double *r2) Consider the quadratic equation: f(x) = a* x2 + b*x+c where a, b and tc are constant coefficients. This equation may have up to 2 real roots. The roots are the values of x for which a * x2 + b * x + c = 0 The roots are given by the equations x1 = (-b+sqrt( D ))/(2* a) x2 = (- b - sqrt(D))/(2* a) where D is the discriminant D = b2 - 4*a* c If D is positive-valued, there are 2 real roots. If D is zero-valued, there is one real root. If D is negative-valued, there are no real roots. If there is one real root, set x1 to its value and leave x2 unchanged. If there are no real roots, leave x1 and x2 unchanged. b) Write a main C program using dynamic memory allocation (malloc, calloc, free...) to input coefficients a, b, c as doubles and pointers to get the 2 roots of quadratic equation which uses the function roots above.

Step by Step Solution

3.45 Rating (142 Votes )

There are 3 Steps involved in it

Step: 1

The detailed ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Operations and Supply Chain Management

Authors: Cecil B. Bozarth, Robert B. Handfield

3rd edition

132747324, 978-0132747325

More Books

Students also viewed these Accounting questions

Question

Please provide steps! I will remember to rate you a thumbs up !

Answered: 1 week ago