CSCE 150                                           Final Exam                                         Dec. 12, 00

Name:____________________________                             SSN: __________

Instructions: Do all of the following questions and show your work.

 

  1. (15 points) Let A be a one-dimensional array whose lower index is 1 and upper index is N. Write a Fortran 90 segment to reverse the elements of A. This should be done without using any other array. This means all the operations have to be performed on A directly. For example, if A has 3 elements and if A(1)=7, A(2)=3, A(3)=8,

then after the reversing process, you should have: A(1)=8, A(2)=3, A(3)=7.

 

 

 

 

 

 

 

 

 

 

 

 

  1. (15 points) Write a Fortran 90 SUBROUTINE whose only input is a positive integer N greater than 3 and whose only output is the sum of integers which are greater than or equal to 3 and are multiples of 3. For example, if N=14, then the output of the SUBROUTINE should be 30. Note: Do NOT display the output.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  1. (15 points) Write a Fortran 90 segment to create a square matrix (call it A) whose number of rows is N and whose elements are all equal to zero except those on the counter diagonal which are equal to 1, 2, 3, …, N. For example, if N=3, then your matrix should be

0          0          1

0          2          0

3          0          0

            If N=4, then your matrix should be

                                    0          0          0          1

                                    0          0          2          0

                                    0          3          0          0

                                    4          0          0          0

            And so on. Note: your program should be general and should work for any value of N.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  1. (10 points)

     (a) Define CPU and RAM.

 

 

 

 

 

 

(b) List two major components of CPU.                       

 

 

 

  1. (15 points) Find all the errors in the following Fortran 90 program.

 

PROGRAM MyProgram

IMPLICIT nonE

INTEGER :: K, M

K=5

M=MyFunc(K)

M=M+1

INCLUDES

      FUNCTION MyFunc(K)

                  INTEGER, INTENT(IN) :: K

                  IF (MOD(K,3)==0) MyFunc=0

                  IF (MOD(K,3)>1)

                              MyFunc=K-2

                  ELSE

                              MyFunc==K-1

                  END IF

      END MyFunc

PRINT *,  “Value is: “, M

END PROGRAM MyprograM

 

 

 

 

 

 

6. (15 points) Implement a RECURSIVE Fortran 90 FUNCTION whose only input is a positive integer N and whose only output is the number of digits contained in N. 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  1. (15 points) Find the output of the following program exactly as it will be displayed on the screen. Assume that the program has no errors.

 

PROGRAM Final_Program

IMPLICIT NONE

INTEGER :: N, J, K, R

INTEGER, DIMENSION(:,:), ALLOCATABLE :: A

N=3

ALLOCATE(A(3,3))

DO J=1, N

      DO K=1, N

                  A(J,K)=4

      END DO

END DO

DO   J=1, N

      DO K=1, J

                  A(J,K)=-9

      END DO

END DO

DO J=1, N

      PRINT *, (A(J,K), K=1, N)

END DO

PRINT *

PRINT *

R=K**2

R=R/2

DO K=1, N

      A(K,K)=R+K

END DO

PRINT *, ((A(J,K), K=1, 2), J=1, 2)

DEALLOCATE(A)

END PROGRAM Final_Program