Wednesday, November 24, 2010

Program to find the root of Quadratic Equation

implicit double precision(a-h,o-z)
write(*,*) “please provide the a,b,c coeff”
read(*,*) A,B,C
D=B*B-4*A*C
if(D.GT.0) then
root1=(-B/(2*A))+(SQRT(D))/(2*A)
root2=(-B/(2*A))-(SQRT(D))/(2*A)
write(*,*) root1,root2
elseif(D.EQ.0) then
root1=(-B/(2*A))
root2=root1
write(*,*) root1,root2
else
root1=(-B/(2*A))+(SQRT(-D))/(2*A)
root2=(-B/(2*A))-(SQRT(-D))/(2*A)
a=(root1+root2)/2
b=(root1-root2)/2
write(*,*) ‘realpartroot=’,a, ‘complexpartroot=’,b
endif
stop
END

7 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. What is the meaning of root1 + root2/2

    ReplyDelete
  3. Using Fortran obtain the root of quadratic question ax^2+6x+c=0

    ReplyDelete
  4. can anyone give me the link to download the exe and batch file for fortran77. I want to use the same for coding!

    ReplyDelete
  5. Fortran program to solve quadratic equation

    ReplyDelete