Write a program to calculate the roots of a quadratic equation.
Write a program to calculate the roots of a quadratic equation.
6 views
1 Answers
import math
a = input(“Enter co-efficient of x^2”)
b = input(“Enter co-efficient of x”)
c = inputfEnter constant term”)
d = b*b - 4*a*c
if d == 0:
print “Roots are real and equal”
root1 = root2 = -b / (2*a)
elif d > 0:
print “Roots are real and distinct”
root1 = (- b + math.sqrt(d)) / (2*a)
root2 = (-b - math.sqrt(d)) / (2*a)
else:
print “Roots are imaginary”
print “Roots of the quadratic equation are”,root1,“and”,root2
6 views
Answered