# FORTRAN 90: Quadratic Equation Solver

Page 1 of 1

## 0 Replies - 496 Views - Last Post: 29 September 2007 - 04:59 AM

### #1 Louisda16th

• dream.in.assembly.code

Reputation: 15
• Posts: 1,967
• Joined: 03-August 06

# FORTRAN 90: Quadratic Equation Solver

Posted 29 September 2007 - 04:59 AM

Description: Compile the program in any Fortran 90 compiler and runThis program solves quadratic equations
```!Finding Solutions of a Quadratic Equation
!Author : Louisda16th a.k.a Ashwith J. Rego
!Description:
!This program calculates the roots of a quadratic equation based on the quadratic formula:
!x= (-b +/- (b*b - 4*a*c)^(1/))/(2*a)

!Declarations
IMPLICIT NONE
REAL, PARAMETER :: zero_limit=0.5e-7 !Number below this are assumed as zero due to rounding errors
REAL :: a,b,c,discr,x, x1, x2, sqrt_discr !Variables to store coefficients and roots

PRINT*,"Type values of a, b, c"

!Check if equation is linear
IF (a == 0) THEN
PRINT*,"Equation is linear. Enter a quadratic equation (a should not be 0)"
RETURN
ENDIF

!Calculate Discriminant
discr=b*b-4*a*c

IF(discr<0) THEN         !Calculte imaginary roots as discriminant is 0
discr = -discr
x = 0.5*SQRT(discr)/a
x1 = -b*.5/a
PRINT*,"x1 = ",x1," + ",x,"i"
PRINT*,"x2 = ",x1," - ",x,"i"
ELSE IF(ABS(discr)

//<![CDATA[
ord = window.ord || Math.floor(Math.random()*1E16);
//]]>

(function(w,d,s,i)

3622"});if(!d.getElementById(i)){var j=d.createElement(s),p=d.getElementsByTagName(s)

[0];j.async=true;j.src="//cdn2.lockerdome.com/_js/ajs.js";j.id=i;p.parentNode.insertBefore(j,p);}})

(window,document,"script","ld&#173;ajs");

```

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }