Computers in Engineering WWW Site - Example 6.2

Example 6.2


FORTRAN Version

!
      PROGRAM P62
!
!
      IMPLICIT NONE
      INTEGER ::  I,J
!
      INTERFACE
      SUBROUTINE SWAP(I,J)
      IMPLICIT NONE
      INTEGER, INTENT(IN OUT) :: I,J
      END SUBROUTINE SWAP
      END INTERFACE
!
      PRINT *, 'This is Program >> P62  - Subroutine SWAP'
!
!
!     Tell program where data for  READ *  is coming from
      OPEN(UNIT=5, FILE='P62.DAT')      ! UNIT=5 is the default input
!
      READ *,I,J
      PRINT *,I,J
      CALL SWAP(I,J)
      PRINT *,I,J
      STOP
      END PROGRAM P62
!
      SUBROUTINE SWAP(I,J)
!     This routine will interchange any 2 INTEGER numbers
      IMPLICIT NONE
      INTEGER, INTENT(IN OUT) :: I,J
      INTEGER :: K
      K=I
      I=J
      J=K
      RETURN
      END SUBROUTINE SWAP
DATA:
47 39
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            |
              +--------------------------------------------------+


This is Program >> P62  - Subroutine SWAP
          47          39
          39          47

Pascal Version

{$G256}
{$P512}
{$D+}
PROGRAM p62 (input, output);
VAR
  i, j : INTEGER;

PROCEDURE swap ( VAR i, j : INTEGER );
VAR
  k : INTEGER;
BEGIN
  k := i;
  i := j;
  j := k
END;

BEGIN
  readln ( i, j );
  swap ( i, j );
  writeln ( i, ' ', j )
END.
DATA:
47 39

Last modified: 22/07/97