308-208 - Computers in Engineering - Previous Midterms

# Midterm Fall 1995

Question 1. (11 minutes, 15 points)

What will the following program output?
```
program main
implicit none
integer :: a,b,c
real :: d,e,f
a = 39/4
b = 5.5-5*4.0
c = mod(19,6)-mod(11,3)+mod(16,4)
d = 17/4*5
e = a
f = ((a/2*c)**2)**2
print *,a,b,c,d,e,f
stop
end program main

```

Question 2: (11 minutes, 15 points)

What does this program prints?
```
program question2
implicit none
!
integer :: A, B, DIV
real    :: EXP
!
print *, 'Hello World!'

do A=13, 19, 4
do B=1, 3
if (mod(A,B) > B/3) then
if (A/6 >= B) then
DIV=A/B
print *, DIV
else
EXP=A**B
print *, EXP
end if
else
print *, 'Nothing...'
end if
end do
end do
stop
end program question2

```

Question 3: (12 minutes, 15 points)

What will the following program print, given the input data below.
```
Program Question3
implicit none
integer :: i , j(100), k(100), n
integer :: a, b

do i = 1,n
end do
do i = 1,n
end do
do i = 1, n-1
a=k(j(i))
b=k(j(i+1))
print *,i,a,b, (a+b)
end do
Stop
End Program Question3

Input data is:-
6
4 1 6 5 3 2
13 27 18 10 23 9

```

Question 4: (11 minutes, 15 points)

What does this program prints?
```

CHARACTER (len=1) :: LETTER(6), OUTPUT(11)
INTEGER :: INDEX(6)
!
LETTER(1) = 'V'
LETTER(2) = 'I'
LETTER(3) = 'A'
LETTER(4) = 'T'
LETTER(5) = 'L'
LETTER(6) = ' '
INDEX(1) = 1
INDEX(2) = 1
INDEX(3) = 6
INDEX(4) = 4
INDEX(5) = 5
INDEX(6) = 3
!
DO  I = 1,11
MORE = MOD(I,4)
IF (MOD(I,2) == 0 .AND. MORE == 0) THEN
J = 3
ELSEIF (MOD(I,2) == 0) THEN
J = 2
ELSE
J = INDEX(I/2+1)
ENDIF
OUTPUT(I) = LETTER(J)
END DO
PRINT *,OUTPUT
STOP
END

```

Question 5. (45 minutes, 40 points)

Write a FORTRAN program using subprograms to calculate the value of "x squared plus y cubed", with initial values of x =3 and y=4. Repeat the process with x and y interchanged.

The exact steps to follow are:-

• Write a FUNCTION XSquare which returns the square of the input parameter.
• Write a FUNCTION YCube which returns the cube of the input parameter.
• Write a SUBROUTINE Swap to interchange two real parameters.
• Use the two functions to calculate "x squared plus y cubed", with the given values, and print out the result.
• Use the subroutine Swap to interchange x and y and repeat the step 4.

End of Midterm