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

#1 Louisda16th   User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • 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)

PROGRAM quadratic
!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"
        READ*, 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)
				







Is This A Good Question/Topic? 0
  • +

Page 1 of 1