Trusted by millions of Kenyans
Study resources on Kenyaplex

Get ready-made curriculum aligned revision materials

Exam papers, notes, holiday assignments and topical questions – all aligned to the Kenyan curriculum.

Write a program that solves a quadratic equation gives the answer for the roots.

Write a program that solves a quadratic equation gives the answer for the roots.

Answers


Martin
#include
#include
#include
float main()
{
float a, b, c, d, x1, x2;
printf("Enter the value of the coefficient of x^2 , x, and c respectively\n");
scanf("%f%f%f", &a, &b, &c);
if (a!=0)
{


d=sqrt(b*b - 4 *a*c);
x1=(-b+d)/(2*a);
x2=(-b-d)/(2*a);
printf("The value of x is equal to %.2f\n and\n %.2f", x1, x2);
}
else
{
printf("\t\t\t\n\n\n\n\a*****Since the value of the coefficient of x^2 is zero, hence the equation ain't a quadratic equation*****\n\n\n");

}
return 0;
}
Joshua_white answered the question on March 8, 2018 at 08:41

Answer Attachments

Exams With Marking Schemes

Related Questions