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

Please make sure the program is compilable and correct before you submit your an

ID: 3531932 • Letter: P

Question

Please make sure the program is compilable and correct before you submit your answer .....Thanks!!!!


Roots of a quadratic equation. Write a program that finds the roots of a quadratic equation using the quadratic formula. Begin by writing a main() function that carries out the following tasks:


a.) Call printf() to prompt the user for the coefficients a, b, and c.

b.) Call scanf() to read the coefficients.

c.) Call quadratic_formula() to compute the roots.

d.) Call printf() to print the results to the standard output, properly labeled.


Once main() is working, write quadratic_formula(). This function should return 0, 1, or 2, depending on whether there are no real roots (roots are imaginary), two equal real roots, or two distinct real roots. It should also compute any real roots and communicate them to main() using call by reference. The main() function should use the value returned by quadratic_formula() to determine how to label the output.

Explanation / Answer

#include #include #include #include int main() { float a,b,c,x1,x2,disc; printf("------------------------------------------------------------- "); printf("----------------made by C code champ ------------------------ "); printf("------------------------------------------------------------- "); printf(" C Program for Calcualting roots of Quadratic Equation "); printf("Enter coefficient of X^2 : "); scanf("%f",&a); printf(" Enter coefficient of X^1 : "); scanf("%f",&b); printf(" Enter coefficient of X^0 : "); scanf("%f",&c); /*Finding discriminant*/ disc=b*b-4*a*c; /*distinct roots*/ if(disc>0) { x1=(-b+sqrt(disc))/(2*a); x2=(-b-sqrt(disc))/(2*a); printf(" The roots are distinct "); printf("x1=%f x2=%f ",x1,x2); getch(); exit(0); } /*Equal roots*/ if(disc==0) { x1=x2=-b/(2*a); printf(" The roots are equal "); printf("x1=%f x2=%f ",x1,x2); getch(); exit(0); } /*complex roots*/ x1=-b/(2*a); x2=sqrt(fabs(disc))/(2*a); printf(" The roots are complex. "); printf("The first root=%f+i%f ",x1,x2); printf("The second root=%f-i%f ",x1,x2); getch(); }