Computers in Engineering WWW Site - Example 3.7

# Example 3.7

#### FORTRAN Version

```!
PROGRAM P38
!
!  This program will find the perimeter and the area of a triangle
!
!
IMPLICIT NONE
REAL :: A,B,C,PERI,SEMI,AREA
INTEGER :: N
!
!    Tell program where data for  READ *  is coming from
OPEN(UNIT=5, FILE='P38.DAT')      ! UNIT=5 is the default input
!
!
!
DO N=1,20
IF( A == -90.0 ) STOP

IF( A <= 0 .OR. B <= 0 .OR. C <= 0 ) THEN
PRINT 5,A,B,C
PRINT *,'ALL THE VALUES MUST BE POSITIVE.'
5         FORMAT(' A=',F8.3,'  B=',F8.3,' C=',F8.3)
ELSE
PERI = A+B+C
SEMI = PERI/2
AREA = SEMI * (SEMI-A) * (SEMI-B) * (SEMI-C)
IF (AREA .LT. 0) THEN
PRINT 5,A,B,C
PRINT *,'TWO SIDES SHORTER THAN THIRD'
ELSE
PRINT 8,A,B,C,PERI,SQRT(AREA)
8            FORMAT(' A=',F8.3,' B=',F8.3,' C=',F8.3,' PERIMETER =', &
F8.3,' AREA=',F8.3)
END IF
END IF
END DO
STOP
END PROGRAM P38
```
DATA:
```5  7  3
5 -2 5
34 62 54
30 5 43
-90 -90 -90
```
OUTPUT:
```
+--------------------------------------------------+
|     32-bit Power for Lahey Computer Systems      |
|   Phar Lap's 386|DOS-Extender(tm) Version 7.0    |
|  Copyright (C) 1986-94 Phar Lap Software, Inc.   |
|           Available Memory = 14880 Kb            |
+--------------------------------------------------+

A=   5.000 B=   7.000 C=   3.000 PERIMETER =  15.000 AREA=   6.495
A=   5.000  B=  -2.000 C=   5.000
ALL THE VALUES MUST BE POSITIVE.
A=  34.000 B=  62.000 C=  54.000 PERIMETER = 150.000 AREA= 916.229
A=  30.000  B=   5.000 C=  43.000
TWO SIDES SHORTER THAN THIRD
```