PROGRAM QuadraticEquations_1
!---------------------------------------------------------------------------------
!	Program to solve a quadratic equation using the quadratic formula.
!
!	Variables used are:
!		A, B, C				: the coefficients of the quadratic equation
!		Discriminant		: the discriminant, B**2 - 4.0*A*C
!		Root_1, Root_2	: the two roots of the equation
!
!	Input		: The coefficients A, B, and C
!	Output	: The two roots of the equation or the (negative) discriminant
!				and a message indicating that there are no real roots
!---------------------------------------------------------------------------------

	IMPLICIT NONE

	REAL A, B, C, Discriminant, Root_1, Root_2
	
	! Get he coefficients
	PRINT *, "Enter the coefficients of the quadratic equation:"
	READ *, A, B, C
	
	! Calculate the coefficients
	Discriminant = B**2 - 4.0*A*C
	
	! Check if discriminant is nonnegative. If it is, calculate and
	! display the roots. Otherwise display the value of the discriminant
	! and a no-real-roots message.
	IF (Discriminant >= 0) THEN
		Discriminant = SQRT(Discriminant)
		Root_1 = (-B + Discriminant) / (2.0 * A)
		Root_2 = (-B - Discriminant) / (2.0 * A)
		PRINT *, "The roots are", Root_1, Root_2
	ELSE
		PRINT *, "Discriminant is", Discriminant
		PRINT *, "There are no real roots"
	END IF
	
	pause
End PROGRAM QuadraticEquations_1



 
 

'노트 > Fortran 연습' 카테고리의 다른 글

Program 4.1. 곱셈표의 출력  (0) 2014.04.27
Program 3.5. 이진 반가수기  (0) 2014.04.06
Program 3.4. 오염지수 3  (0) 2014.04.06
Program 3.3. 오염지수 2  (0) 2014.04.06
Program 3.2. 오염지수  (0) 2014.04.06
Program 2.Exercise6.2. 온도 변환 (2nd Version)  (0) 2014.03.23
Program 2.Exercise6.1. 온도 변환 (1st Version)  (0) 2014.03.23
Program 2.Exercise5  (0) 2014.03.23
Program 2.1. 발사체 문제  (0) 2014.03.22
Program 1.Exercise10  (0) 2014.03.22

+ Recent posts