Upload
victor-cannon
View
212
Download
0
Embed Size (px)
Citation preview
Quadratic Equations
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
Logical Circuits
Sum = (A + B) . (A . B)
Carry = A . B
+.
Logical Circuits
Sum = (A + B) . (A . B)
Carry = A . B
+.
Sum = (A .OR. B) .AND. .NOT. (A .AND. B)Carry = A .AND. B
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
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
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