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

Hi, I need help writing A C program using pointers. Here is the description: Wri

ID: 3641988 • Letter: H

Question

Hi,
I need help writing A C program using pointers. Here is the description:


Write a function 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) – j(*r2)

Explanation / Answer

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

{

if ( a == b && b==0)

{

return 1;

}

else if(a == 0 && b!=0)

{

*r1 = (-c)/b ;

return 2;

}

else if(b*b-4*a*c >=0)

{

*r1 =( -b + sqrt(b*b-4*a*c) )/ (2*a);

*r2 =( -b - sqrt(b*b-4*a*c) )/ (2*a);

return 3;

}

else

{

*r1 = (-b)/ (2*a);

*r2 = sqrt(4*a*c-b*b) / (2*a) ;

return 4;

}

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