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

Your first program is a simple mathematical calculation program. A quadratic (se

ID: 3543062 • Letter: Y

Question

Your first program is a simple mathematical calculation program. A quadratic (second order polynomial) equation ax2 + bx + c = 0; can be solved by the formulas:

Write a C program that shows a menu to get 3 integer values from the user, namely, a, b, and c, and then calculates and returns the values for x1 and x2 to the above formula.

Your program should prompt the user for these values, accept input from the keyboard, and then print out the result.

Include a report in the Word file that shows the results for the following values:

1) (2,3,5)

2) (3,6,5)

3) (1,9,2)

You may use the function double sqrt (double), found in <math.h>, to calculate the square root.

Explanation / Answer

#include<stdio.h>

#include<math.h>

#include<conio.h>

int main()

{

float a,b,c,x1,x2;

printf(" Enter the values of a,b,c for finding roots of a quadratic eq: ");

scanf("%f %f %f",&a,&b,&c);


/*checking of condition whether determinant is geater or equal to zero*/

if(b*b >= (4*a*c))

{

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

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

printf(" the roots of the equation are ");

printf(" x1= %f x2=%f",x1,x2);

}

else

printf(" the roots are imaginary Roots.");

getch();

return 0;

}


1) for (2,3,5)=========> the roots are imaginary (b*b< 4*a*c)

2) for (3,6,5)=========> the roots are imaginary (36-60 < 0)

3) for (1,9,2)=========> (9^2- 4*1*2 = 73 >0) hence x1= -0.2279 x2= -8.77



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