Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This assignment will require you to do arithmetic in C involving multiple conditional paths and multiple functions separating out parts of the code. Specifically, your
This assignment will require you to do arithmetic in C involving multiple conditional paths and multiple functions separating out parts of the code. Specifically, your assignment is to write a program implementing the quadratic formula. Start with three floating point variables named a, b and c. Prompt the user for each of them as we have shown how to do in class, and accept them as input. You will then compute the roots x1 and X2, and printf them out as part of an appropriate message. However, you've got three complications to deal with: In certain cases, quadratic equations have only one root. In that case you should print out only that one root. In certain cases, quadratic equations have one or more complex roots. In that case you should print out both the real and imaginary part of the roots. The quadratic formula is invalid if a = 0. You may simply print an error in this case. I also require the following: Do no arithmetic in main(). Create functions that do all your math. Declare a, b and c in main() - along with any other variables you need. Pass your a, b, and c values to your functions, and results back from your functions. Do not use any global variables. You must specifically use a function to compute the discriminant - the part of the quadratic under the square root. . (Hint: This can also help you figure out when you have complex roots!) o The discriminant function should have the following header: double discriminant(double a, double b, double c) Comment every function, every "paragraph" of code as we discussed in class, and any line of code that does more than two things. Indent your code properly. Your editor will do this for you! Let it. Here's one hint: Include along with any other library headers you need. This will let you use the sqrt() function to compute square roots. o sqrt() works exactly like you hope it does - sqrt(x), for a double value x, returns its square root. sqrtf() does the same thing for float values. You can assign the return value to an intermediate variable or use it right in the middle of an equation. o We'll be talking much more about the math library and other libraries soon enough
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started