next up previous contents
Next: Mathematical Magic Up: The `Triangle Program' Previous: The `Triangle Program'

Solution

    PROGRAM Triangle
     IMPLICIT NONE
     LOGICAL l1, l2
     INTEGER side1, side2, side3
      PRINT*, "Type in the three sides:"
      READ*, side1, side2, side3
      IF (2*MAX(side1,side2,side3) .GE. side1+side2+side3) THEN
       PRINT*, "Not a Triangle"
      ELSE
       l1 = side1 .EQ. side2
       l2 = side2 .EQ. side3
       IF (l1 .AND. l2) THEN
        PRINT*, "Equilateral"
       ELSE
        IF (l1 .OR. l2 .OR. side1 .EQ. side3 ) THEN
         PRINT*, "Isosoles"
        ELSE
         PRINT*, "Scalene"
        END IF
       END IF
      END IF
    END PROGRAM Triangle

The results are

  1. (1, 1, 1) -- equilateral
  2. (2, 2, 1) -- isos
  3. (1, 1, 0) -- not a triangle
  4. (3, 4, 5) -- scalene
  5. (3, 2, 1) -- not a triangle (a straight line)
  6. (1, 2, 4) -- not a triangle


next up previous contents
Next: Mathematical Magic Up: The `Triangle Program' Previous: The `Triangle Program'

©University of Liverpool, 1997
Thu May 29 10:11:26 BST 1997
Not for commercial use.