{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

(12) Functins Subroutines (Sina)

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

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

Functions and Subroutines Sina Meraji Fall 2009

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

View Full Document
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
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

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

View Full Document
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