! PROGRAM P63 ! ! Multiple CALLs to a SUBROUTINE ! IMPLICIT NONE INTEGER :: I,J,M,N ! INTERFACE SUBROUTINE SWAP(I,J) IMPLICIT NONE INTEGER, INTENT(IN OUT) :: I,J END SUBROUTINE SWAP END INTERFACE ! PRINT *, 'This is Program >> P63 - Multiple subroutine CALLs' ! ! Tell program where data for READ * is coming from OPEN(UNIT=5, FILE='P63.DAT') ! UNIT=5 is the default input ! READ *,I,J PRINT *,I,J CALL SWAP(I,J) PRINT *,I,J PRINT * ! Leave a blank line READ *,M,N PRINT *,M,N CALL SWAP(M,N) PRINT *,M,N PRINT * ! Leave a blank line CALL SWAP(I,J) PRINT *,I,J STOP END PROGRAM P63 ! 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 SWAPDATA:
10 27 15 43OUTPUT:
+--------------------------------------------------+ | 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 >> P63 - Multiple subroutine CALLs 10 27 27 10 15 43 43 15 10 27
{$G256} {$P512} {$D+} PROGRAM p63 (input, output); VAR i, j, m, n : 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 ); readln ( m, n ); swap ( m, n ); writeln ( m, ' ', n ); swap ( i, j ); writeln ( i, ' ', j ) END.DATA:
10 27 15 43
Last modified: 22/07/97