Wednesday, 29 February 2012

Squre roots of a quadratic equation programme in python



#  ax2 + bx + c = 0. Recall that such an equation has two
#solutions for the value of x, and these are given by the formula
#          x = -b +- sqrt(b2 – 4ac) / 2a


import math


a=input("Enter the value of a")
b=input("Enter the value of b")
c=input("Enter the value of c")


d=(b*b-4*a*c)
d=math.sqrt(d) #predefine function in python


root1=(-b+d)/2*a
root2=(-b-d)/2*a


print 'first root is',root1
print '\nsecond root is',root2

No comments:

Post a Comment

Compiler for C,C++ and Python {paste your programme to see the output}