Fortran examples

Fortran examples

Hopefully this helps!

Here is some sample Fortran code:

C AREA OF A TRIANGLE - HERON'S FORMULA

	C INPUT - CARD READER UNIT 5, INTEGER INPUT

	C OUTPUT - LINE PRINTER UNIT 6, REAL OUTPUT

	C INPUT ERROR DISPAY ERROR OUTPUT CODE 1 IN JOB CONTROL LISTING

	      INTEGER A,B,C

	      READ(5,501) A,B,C

	  501 FORMAT(3I5)

	      IF(A.EQ.0 .OR. B.EQ.0 .OR. C.EQ.0) STOP 1

	      S = (A + B + C) / 2.0

	      AREA = SQRT( S * (S - A) * (S - B) * (S - C))

	      WRITE(6,601) A,B,C,AREA

	  601 FORMAT(4H A= ,I5,5H  B= ,I5,5H  C= ,I5,8H  AREA= ,F10.2,12HSQUARE UNITS)

	      STOP

	      END

test signature
3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I especially liked it where you said:

C AREA OF A TRIANGLE - HERON'S FORMULA

	C INPUT - CARD READER UNIT 5, INTEGER INPUT

	C OUTPUT - LINE PRINTER UNIT 6, REAL OUTPUT

	C INPUT ERROR DISPAY ERROR OUTPUT CODE 1 IN JOB CONTROL LISTING

	      INTEGER A,B,C

	      READ(5,501) A,B,C

	  501 FORMAT(3I5)

	      IF(A.EQ.0 .OR. B.EQ.0 .OR. C.EQ.0) STOP 1

	      S = (A + B + C) / 2.0

	      AREA = SQRT( S * (S - A) * (S - B) * (S - C))

	      WRITE(6,601) A,B,C,AREA

	  601 FORMAT(4H A= ,I5,5H  B= ,I5,5H  C= ,I5,8H  AREA= ,F10.2,12HSQUARE UNITS)

	      STOP

	      END

Testing signature.

This is a very advanced Fortran compiler ! printing the program listing  in color?  I never had this luxury !
 

Leave a Comment

Please sign in to add a comment. Not a member? Join today