CSCE 150 Exam I 10/25/2000
Name: SS#:
(1) (30 points) Write a Fortran 90 FUNCTION which calculates N!. Call the function MyFunction. The input for the function is a positive integer N and the output is N!.
(2) (45 points) Find the output of the following segments:
(a) In the following SUM is a variable of type INTEGER.
---------------------
SUM=0
DO J=1,3
SUM=SUM+J*J
END DO
PRINT *, “Sum= “, SUM
--------------------
Output:
(b) In the following X and Y are variables of type REAL.
-----------------
X=2.3
IF (X<1.0) THEN
Y=100*X
ELSE IF (X>2.5) THEN
Y=10*X
ELSE
Y=2*X
END IF
PRINT *, “The value of Y is: “, Y
------------------
Output:
(c) Find the value of MyProd(3).
----------------
FUNCTION MyProd(K)
IMPLICIT NONE
INTEGER, INTENT(IN) :: K
INTEGER :: MyProd, I
MyProd=1
DO I=1, K
MyProd=MyProd*2
END DO
END FUNCTION MyProd
------------------
MyProd(3)=
(3) (25 points) Find all the errors in the following program:
PROGRAM MyProgram
IMPLICIT NoNe
INTEGER : L, M, N
N=MOD(7:N)
N=2
IF (N=3) THEN
PRINT *, “There is an error in this statement”
END IF
M=My_Function(2)
CONTAINS
FUNCTION My_Function(R)
INTEGER, INTENT(IN) :: R
IF (R<2) THEN
My_Function=R
ELSE
R=2*R
My_Function=R
END IF
END My_Function
PRINT *, “M= “, M
END MyProgram