7
Quadratic Equations

Quadratic Equations. PROGRAM QuadraticEquations_1 IMPLICIT NONE REAL A, B, C, Discriminant, Root_1, Root_2 ! Get the coefficients PRINT *, "Enter the

Embed Size (px)

Citation preview

Page 1: Quadratic Equations. PROGRAM QuadraticEquations_1 IMPLICIT NONE REAL A, B, C, Discriminant, Root_1, Root_2 ! Get the coefficients PRINT *, "Enter the

Quadratic Equations

Page 2: Quadratic Equations. PROGRAM QuadraticEquations_1 IMPLICIT NONE REAL A, B, C, Discriminant, Root_1, Root_2 ! Get the coefficients PRINT *, "Enter the

PROGRAM QuadraticEquations_1

IMPLICIT NONE REAL A, B, C, Discriminant, Root_1, Root_2

! Get the coefficients PRINT *, "Enter the coefficients of the quadratic equation:" READ *, A, B, C

! Calculate the discriminant Discriminant = B**2 - 4.0*A*C

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

END PROGRAM QuadraticEquations_1

Page 3: Quadratic Equations. PROGRAM QuadraticEquations_1 IMPLICIT NONE REAL A, B, C, Discriminant, Root_1, Root_2 ! Get the coefficients PRINT *, "Enter the

Logical Circuits

Sum = (A + B) . (A . B)

Carry = A . B

+.

Page 4: Quadratic Equations. PROGRAM QuadraticEquations_1 IMPLICIT NONE REAL A, B, C, Discriminant, Root_1, Root_2 ! Get the coefficients PRINT *, "Enter the

Logical Circuits

Sum = (A + B) . (A . B)

Carry = A . B

+.

Sum = (A .OR. B) .AND. .NOT. (A .AND. B)Carry = A .AND. B

Page 5: Quadratic Equations. PROGRAM QuadraticEquations_1 IMPLICIT NONE REAL A, B, C, Discriminant, Root_1, Root_2 ! Get the coefficients PRINT *, "Enter the

PROGRAM Half_Adder

!-----------------------------------------------------------------------! Program to calculate the outputs from a logical circuit that! represents a binary half-adder. Variables used are:! A, B : the two logical inputs to the circuit! Sum, Carry : the two logical outputs!! Input: The two logical inputs A and B! Output: The two logical outputs Sum and Carry, which represent the! sum and carry that result when the input values are added!-----------------------------------------------------------------------

IMPLICIT NONE LOGICAL :: A, B, Sum, Carry

PRINT *, "Enter logical inputs A and B:" READ *, A, B Sum = (A .OR. B) .AND. .NOT. (A .AND. B) Carry = A .AND. B PRINT *, "Carry, Sum =", Carry, Sum

END PROGRAM Half_Adder

Page 6: Quadratic Equations. PROGRAM QuadraticEquations_1 IMPLICIT NONE REAL A, B, C, Discriminant, Root_1, Root_2 ! Get the coefficients PRINT *, "Enter the

IF Construct

IF (ReynoldsNumber < LowCutoff) THEN PRINT *, "Flow is laminar" ELSE IF (ReynoldsNumber < HighCutoff) THEN PRINT *, "Flow is unstable" ELSE PRINT *, "Flow is turbulent" END IF

Page 7: Quadratic Equations. PROGRAM QuadraticEquations_1 IMPLICIT NONE REAL A, B, C, Discriminant, Root_1, Root_2 ! Get the coefficients PRINT *, "Enter the

CASE Construct

SELECT CASE (Index ) CASE (:LowCutoff - 1) PRINT *, "Good condition" CASE (LowCutoff : HighCutoff - 1) PRINT *, "Fair condition" CASE (HighCutoff:) PRINT *, "Poor condition" END SELECT