Friday, 6 July 2018

11th CS Prog-7

#to find the roots of the quadratic equation
a=float(input("Enter a value: "))
b=float(input("Enter b value: "))
c=float(input("Enter c value: "))
print("a =",a,"b =",b,"c =",c)
#finding discrimunmant
D=b*b-4*a*c
print("Discriminant = ",D)
#logic
if D>0:
 R1=((-b+(D)**0.5)/(2*a))
 R2=((-b-(D)**0.5)/(2*a))
 print("R1 =",R1, " R2=",R2)

elif D==0:
   R1=R2=-b/(2*a)
   print("Roots are equal =",R1)
else:
   print("Imaginary number")
   

No comments:

Post a Comment