Please Circle Your Section:: Key Solution (A)
Please Circle Your Section:: Key Solution (A)
ID #
SM SM
AL-MULHEM 9:00-9:50 13:10-14:00
UT UT
MLAIH 9:00-9:50 11:00-11:50
UT UT UT
SECTION AL-HASHIM 8:00-8:50 10:00-10:50 13:10-14:00
SM UT UT
BAQAIS 11:00-11:50 7:00-7:50 14:10-15:00
SM SM SM SM
AL-YOUSEF 7:00-7:50 8:00-8:50 10:00-10:50 13:10-14:00
B = 4.52
C = 8.958
D = 87.45
M = 724
PRINT 5, B, M, 'KFUPM'
5 FORMAT (1X, F5.3, I4, 2X, A)
PRINT 15, D, 'DHAHRAN', C
15 FORMAT ('0', F4.2, A9, F5.2)
PRINT 25, C, M, '1.999', B
25 FORMAT (' ', F6.4, 1X, I2, 1X, A3, F3.1)
END
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
4 . 5 2 0 7 2 4 K F U P M
* * * * D H A H R A N 8 . 9 6
8 . 9 5 8 0 * * 1 . 9 4 . 5
What will be the values of array X after executing the following program?
INTEGER X(5,2)
OPEN (UNIT=10,FILE ='INPUT1.DAT',STATUS= 'OLD')
OPEN (UNIT=20,FILE ='INPUT2.DAT',STATUS= 'OLD')
READ (10,*)((X(I,J),J=1,2),I=2,4,2)
READ (20,*)((X(J,I),J=1,5,2),I=1,2)
DO 1 I = 1,5 X
1 PRINT*, (X(I,J),J=1,2)
END 14 19
INPUT1.DAT file INPUT2.DAT file
8 9
8 14
9 16
11 15 16 20
13 19
10 20
99 30
11 13
15 30
Question 3 (2 Points):
How many lines of 'ICS 101' does the following code print out?
DO 10 M=3,14,2
DO 10 N=12,1,-2
PRINT*, 'ICS 101' 36
10 CONTINUE
END
Form (A)
Question 4 (8 POINTS):
INTEGER A(0:1,-2:1)
Memory
7
10
9
6
1
3
1
4
What will be the output of the following code?
7 10
3 4
Hint: Print question mark ? for any printed variable with un-initialized
(undefined) value.
INPUT:
40 45 60 19
30 55 50
30 ? 50
40 60 60
Form (A)
a. b.
READ*,((A(K,J),K=1,5),J=1,3) READ*,((A(J,K),J=1,3),K=1,5)
d.
c.
DO 20 J = 1, 5
READ*, (A(K,J),K=1,3)
READ*,((A(K,J),J=1,5),K=1,3)
20 CONTINUE
5A
[3] To convert R x to FORTRAN statement, we write:
3B
a. R = ABS(x – (5*A)/(3*B))
b. R = CALL ABS(x – (5*A)/(3*B))
c. R = CALL (ABS(x – (5*A)/(3*B)))
d. R = CALL SUBROUTINE ABS(x – (5*A)/(3*B))
e. None of the above, because FORTRAN doesn’t have an intrinsic
function ABS
[4] Assume that you would like to open the file EXAM.DAT for writing,
and you don’t know if this file exists or not. In case you do NOT
want to overwrite the contents of the file if it already exists,
then what is the correct way to open this file?
a. OPEN(UNIT=3,FILE='EXAM.DAT',STATUS='OLD')
b. OPEN(UNIT=3,FILE='EXAM.DAT',STATUS='NEW')
c. OPEN(UNIT=3,FILE='EXAM.DAT',STATUS='UNKNOWN')
d. REWIND('EXAM.DAT')
e. REWIND(3)
Form (A)
DO 10 C = 1,9
PRINT*,(X(R,C),R = 1,6)
10 CONTINUE
Complete the missing parts to obtain the sum of the elements
of row 4
SUM = 0
DO 20 C = 1,9
SUM = SUM + X(4,C)
20 CONTINUE
Complete the missing parts to obtain the maximum element
value in column 2
MAX = X(1,2)
DO 30 R = 2,6
IF (X(R,2).GT. MAX) MAX = X(R,2)
30 CONTINUE
Form (A)
28000 93 A+
27000 78 B+
26000 50 D
. . .
. . .
. . .
Note: Assume that only one student is at the cutting edge of C+. Don’t
forget to close all opened files after you are done.
Write a FORTRAN program that reads a 2-D integer array MAT of size 5x8
row-wise. It then reads an integer value M. The program should test all
elements in MAT on whether they are dividable by M or not. Every time the
program finds an element in MAT that is dividable by M, it stores the row
and column indices of the corresponding location into array LOC which is
declared of size 40x2. After finishing the search, the program should
print the number of elements in MAT that are dividable by M, and the row
and column indices of the locations of those elements. Output should be: