Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function in in C LANGUAGE that solves the quadratic equation ax 2 + bx +

ID: 3533417 • Letter: W

Question

  Write a function in in C LANGUAGE that solves the quadratic equation ax2 + bx + c = 0. The prototype of the function should be:

int quadratic(double a, double b, double c, double* r1, double* r2);

When called, the function should do the following:

o   If a and b are both 0 it should return 1, indicating that this is not an equation

o   If a is 0 and b is not 0, it should return 2, indicating that this is a linear equation and there is one real root. It should put the root in *r1.

o   If the equation has two real roots, it should return 3 and put the two roots in *r1 and *r2.

o   If the equation has two complex roots, it should return 4 and put the real part in *r1 and the imaginary part in *r2. The roots are (*r1) + j(*r2) and (*r1)

Explanation / Answer

I have successfully executed without any errors


#include <stdio.h>
#include <math.h>
int main(void)
{
double a,b,c,root1,root2;
printf(" Please enter a ");
scanf("%lf",&a);
printf(" Please enter b ");
scanf("%lf",&b);
printf(" Please enter c ");
scanf("%lf",&c);
root1 = (-b + sqrt(b*b-4.*a*c) ) / (2.*a);
root2 = (-b - sqrt(b*b-4.*a*c) ) / (2.*a);
printf(" First root is %lf ",root1);
printf(" Second root is %lf ",root2);
printf(" ");
return 0;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote