# Program to find solution of a quadratic equation
a,b,c=input("Enter the values of a,b,c:").split(",")
a=float(a)
b=float(b)
c=float(c)
dis=b*b-4*a*c
from math import *
if dis>=0:
x1=(-b+sqrt(dis))/(2*a)
x2=(-b-sqrt(dis))/(2*a)
print("The solutions for the given equation are ",x1,"and",x2)
else:
from cmath import *
xr=-b/(2*a)
xi=sqrt(dis)/(2*a)
print("The 1st solution for the given equation is ",xr,"+",xi)
print("The 2nd solution for the given equation is ",xr,"-",xi)
a,b,c=input("Enter the values of a,b,c:").split(",")
a=float(a)
b=float(b)
c=float(c)
dis=b*b-4*a*c
from math import *
if dis>=0:
x1=(-b+sqrt(dis))/(2*a)
x2=(-b-sqrt(dis))/(2*a)
print("The solutions for the given equation are ",x1,"and",x2)
else:
from cmath import *
xr=-b/(2*a)
xi=sqrt(dis)/(2*a)
print("The 1st solution for the given equation is ",xr,"+",xi)
print("The 2nd solution for the given equation is ",xr,"-",xi)
Comments
Post a Comment