{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

(12) Functins Subroutines (Sina)

(12) Functins Subroutines (Sina) - Functions and...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Functions and Subroutines Sina Meraji Fall 2009
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Review PROGRAM sumOfFactorials IMPLICIT NONE INTEGER :: n1,n2, result,I INTEGER :: Fact1, Fact2 INTEGER :: Factorial READ (*,*) n1 ! Input n1 Fact1 = Factorial (n1) READ (*,*) n2 ! Input n2 Fact2 = Factorial (n2) result = Fact1 + Fact2 ! C = A! + B! WRITE (*,*) “A! + B! = “,result END PROGRAM sumOfFactorials Factorial Function
Background image of page 2
PROGRAM sumOfFactorials IMPLICIT NONE INTEGER :: n1,n2, result,I INTEGER :: Fact1, Fact2 INTEGER :: Factorial READ (*,*) n1 ! Input n1 Fact1 = Factorial (n1) READ (*,*) n2 ! Input n2 Fact2 = Factorial (n2) result = Fact1 + Fact2 ! C = A! + B! WRITE (*,*) “A! + B! = “,result END PROGRAM sumOfFactorials ! Computes the Factorial of n INTEGER FUNCTION Factorial ( n ) IMPLICIT NONE INTEGER :: n, value, i value = 1 DO i = 1,n value = value*i END DO Factorial = value END FUNCTION Factorial
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
How Are Arguments Initialized? It is not as simple as it might seem In general it varies from language to language There are 2 RULES that FORTRAN uses
Background image of page 4