Skip to main content

QUADRAT.F95

	PROGRAM QUADRAT
!
!  Purpose: To find the real solutions of the equation
!           a x**2 + b x + c = 0
!
	IMPLICIT NONE
	REAL:: A,B,C,X1,X2,DELTA
!
	WRITE(*,*)'Enter the coefficients a, b and c.'
	READ(*,*)A,B,C
	WRITE(*,*)'You have entered ',A,B,C
	IF(A == 0.0)THEN
!  The next statement is continued on the following line... 
	   WRITE(*,*)'The coefficient a is zero: the equation is linear,',&
             ' not quadratic.'
	   STOP
	END IF
!
	DELTA=B**2-4.0*A*C
	IF(DELTA < 0.0)THEN
	   WRITE(*,*)'The solutions are complex.'
	ELSE
	   X1=(-B+SQRT(DELTA))/(2.0*A)
	   X2=(-B-SQRT(DELTA))/(2.0*A)
	   WRITE(*,*)'The solutions are: ',X1,X2
	ENDIF
!
	END PROGRAM QUADRAT