e..Write a program to find the roots of a quadratic equation.
Answers
## This is gonna be a really interesting program!
print("Formula for the quadratic Equation is ax² + bx + c = 0") # First I'll print the formula of the quadratic equation.
## Now we'll have to take the values of a, b, c to find the roots of the quadratic equation.
a=float(input("Enter the value of a : "))
b=float(input("Enter the value of b : "))
c=float(input("Enter the value of c : "))
## I'm taking the variable 'disc' for the discriminant.
disc = b**2-(4*a*c) # This will give me the value of the discriminant.
d= disc**0.5 # I took 'd' for the square root of the discriminant. And for the square root I used d raised to the power 0.5
## Now let's put a condition.
if disc==0:
root = -b/(2*a)
print("Root of the quadrilateral =", round(root, 2))
elif disc>0:
root1 = (-b+d)/(2*a)
root2 = (-b-d)/(2*a)
print("Root 1 =",round(root1, 2), "and Root 2 =", round(root2, 2))
else:
print("This quadratic equation does not have real roots.")
## You can use 'root1=(-b-d)/(2*a)' and 'root2=(-b-d)/(2*a)' for getting a complex value as the the value will be imaginary.
# root1 = (-b-d)/(2*a)
# root2 = (-b+d)/(2*a)
# print("Root 1 =", root1, "and Root 2 =", root2)
Program to Find Roots of a Quadratic Equation. #include <math.h> double a, b, c, discriminant, root1, root2, realPart, imagPart; printf("Enter coefficients a, b and c: "); scanf("%lf %lf %lf", &a, &b, &c); discriminant = b * b - 4 * a * c; // condition for real and different roots. if (discriminant > 0) {