Computers in Engineering WWW Site - Example 4.9

Example 4.9

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
```

Pascal Version

```PROGRAM p48 (input, output);
{
Program to calculate circumference, area, and volume
}
VAR
pi, circum, area, vol, r : REAL;
n : INTEGER;
BEGIN
writeln ( ^l );
writeln ( ' ':7, 'rad', ' ':5, 'cir', ' ':5, 'area', ' ':5, 'vol' );

pi := 3.14159;

r := 1;
WHILE ( r <= n ) DO
BEGIN
circum := 2.0 * pi * r;
area := pi * sqr(r);
vol := ( 4.0 / 3.0 ) * pi * r * r * r;
writeln ( r:9:2, circum:9:2, area:9:2, vol:9:2 );
r := r + 0.5
END; { end while }
writeln ( ^l )
END.
```
DATA:
```7
```