أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
Write a program that gives us the solution to the quadratic equation i.e. the value of x: ax^2+bx+c=0 The solution for this equation can be found using the quadratic formula x=(-b±√(b^2-4ac))/2a
Please fidn the C program which will give you the answers.
#include <stdio.h>
#include <math.h>
int main()
{
double a, b, c, deter, root1,root2, rlans, imgans;
printf("Enter the values for a, b and c \\n");
scanf("%lf %lf %lf",&a, &b, &c);
deter = b*b-4*a*c;
if (deter > 0)
{
root1 = (-b+sqrt(deter))/(2*a);
root2 = (-b-sqrt(deter))/(2*a);
printf("root1 = %.2lf and root2 = %.2lf",root1 , root2);
}
else if (deter == 0)
{
root1 = root2 = -b/(2*a);
printf("root1 = root2 = %.2lf;", root1);
}
else
{
rlans = -b/(2*a);
imgans = sqrt(-deter)/(2*a);
printf("root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", rlans, imgans, rlans, imgans);
}
return 0;
}