You are on page 1of 4

75 Minutes

17.04.2012 17:40

CENG200 Midterm Exam

There are 30 questions (each 3.34 points) for a total of 100 points.
Exam Type: A
All questions are multiple choice, no points will be lost for wrong answers.
Name:
Student ID:
Section:
Signature:
AAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAA
1) Which of the below is the correct order of a
5) The mathematical theorem below
if a b then a (a+b)/2 b
FORTRAN program?
a) Declarations
b) Executable statements
can be expressed in FORTRAN as:
Executable statements
Declarations
a) if ( a<= b ) then
STOP
STOP
(a <= (a + b) / 2) .OR. (b >= (a + b) / 2)
END
END
endif None of the above
c) Executable statements
d) Declarations
b) if ( a <= b ) then
STOP
STOP
print*, (a + b) / 2
Declarations
Declarations
endif
END
END
c) x = ( a <= b );
e) STOP
y = ( a <= (a + b) / 2);
END
z = ( b >= (a + b) / 2);
Declarations
if (x) then y .AND. z
Executable statements
endif
END
d) if ( a <= b)
if ( a <= (a + b) / 2 <= b) then
print*, (a + b) / 2
2) Which of the segments causes an error?
endif
a) print*, "enter a number"
read*,m
e) None of the above
print*,m
b) print*,"enter a number" !
read*,m
6) What is the output of the program below?
read*,m
real x
print*,m,m
x = 25.025
c) print*, "enter a number"
i=x
read*,m
if ( mod ( i , 5 ) .eq. 0) then
m=2
write ( * , 5 ) sqrt ( x )
print*,m
else
d) read*,v
write( * , 5 ) sqrt ( x + 11 )
print*, "enter m"
endif
print*,v
print* , x
e) print*,"enter m"
stop
read*,m
5 format( f5.0 )
stop
end
print*,m
a) 5.0
b) 5
c) 6
d) 6.0
e) 5.0
3) What is the content of variable x after the
execution of the segment below?
integer a , b
a=5
b=9
x=a/b
a) 0.5

b) 0

c) 0.00000 d) 0.55555 e) 0.55556

4) What is the output of the fragment below?


real a , b
a=5
b=9
k=a/b
print*, k
a) 0.00000 b) 0

c) 0.5

d) 0.55555

e) 0.55556

25.025

25.03

25.0525

25.03

25

7) What is printed by the following FORTRAN


program?
x=2
z=1
w = 3.0
m = x / ( x z ) + w * x ** z ** 2
print* , m
end
a) 8.0
b) 6
c) 8
d) 6.0
e) None of them

AAAAAAAAAAAAAAAAAAAAAAA
8) What is printed by the following statements?
(letter B is used for blank/space character)
k1 = 789
k3 = - 157
x1 = 367.25
x3 = 36.725
write ( * , 5 ) k1 , k3 , x1 , x3
5
format ( i4 , i3 , 2 ( f6.1 ) )
a) B789-157B367.3BB36.7
b) B789-157367.3BBB36.7
c) B789***B367.2BB36.7
d) B789***B367.2BB36.8
e) B789***B367.3BB36.7
9) Which lines in the below program has a syntax
(compilation) error?
1
! summation of even numbers
up to 100
2
integer sum , number
3
sum = 0.0
4
read*, number=2
5
5
sum = sum + number
6
if (number .LT. 100) goto 9
7
print*, sum
8
stop
9
9
number = number + 2
10
goto 5
11
stop
12
end
a) Line3 and Line6 b) Line 4
c) Line11
d) Line1 and Line3
e) Line 8 and Line11
10) What is the output of the following program?
m=2
ic = 0
10
ic = ic + 1
l=1
lc = 3
20
if (lc - 12) 30, 30, 40
30
l = l + ic
lc = lc + m
goto 20
40
print*, l
if (lc .LT. 8) goto 10
stop
end
a) 6 b) 5
c) 4
d) 3
e) 8
11) What is the value of x after the execution of the
segment below?
real x
x=4/2*(1/2)
a) 0
b) 0.0
c) 2.0
d) 1.0
e) Error

AAAAAAAAAAAAAAAAAAAAAAA
12) What is the content of x after the execution of the
program below?
integer x
x = 4/ (2 * ( 3 / 4))
print*, x
end
a) 1.0
b) 0.0
c) 0
d) 2.0
e) Error

13) What is the output of the segment below?


i=5
if ( i 1 ) 4, 5, 6
4
print*, "1"
5
print*, "2"
6
print*, "3"
end
a) 3
b) 1 c) 2
d) 2
e) 3
2
3
2
3
1

14) What is the output of the program below?


i=5
goto (4, 5, 6) i - 1
4
print*, "1"
5
print*, "2"
6
print*, "3"
end
a) 1
b) 3
c) 2
d) 2
e) 3
2
3
2
3
1
15) What will be printed by the following
FORTRAN program?
i = -2
if ( i + 2 ) 5 , 6 , 5
5
if ( i .EQ. -1) then
print*, "B"
else
print*, "C"
endif
6
print*, "D"
end
a) A

b) B

c) C

d) D

e) No Output

AAAAAAAAAAAAAAAAAAAAAAA
16) How many of those evaluate to
.TRUE. if IA = 5 , B = 10.0 , C = 15.0 and FLAG = .TRUE.

AAAAAAAAAAAAAAAAAAAAAAA
21) Which if structure describes the partial
function below?

1) C .EQ. IA + B .OR. .NOT. FLAG


2) A. NE. 7 .AND. FLAG .OR. C .GE. 6
3) .NOT. (B .LE. 12 ) .AND. MOD ( IA , 2 ) .EQ. 0
4) .NOT. ( IA .GT. 5 .OR. C .LT. IA + B )
a) 0
b) 1
c) 2
d) 3
e) 4
17) What is the output produced by the following
program?
k = 10
i=1
10 if ( i > k ) stop
if ( mod ( i , 2 ) .EQ. 0 ) then
k=k/3
else
if ( mod ( i , 3 ) .EQ. 0 ) then
k=k/2
else
k=k*2
endif
endif
print*, i , k
i=i+1
goto 10
end
a) 1 20 b) 1 20 c) 1 20 d) 1 20
2 6
2 6
2 6
2 6
3 3
3 2
3 3
4 3
0 0
0 1

e) 1 20
1 6
3 2

a)

b)

if ( x .GE. 0.0 .AND . y >=0 ) then


f(x,y) = x + y
else if ( x .GE. 0.0 .AND. y .LT. 0) then
f(x,y) = x + y * y
else if ( x .LT. 0.0 .AND. y .GE. 0) then
f(x,y) = x * x + y
else
f(x,y) = x * x + y * y
endif

c)

if ( x .GE. 0.0 .AND .y >=0 ) then


f=x+y
else if ( x .GE. 0.0. AND. Y .LT. 0) then
f=x+y*y
else if ( x .LT. 0.0 .AND. y .GE. 0) then
f=x*x+y
else if ( x .LT. 0.0 .AND. y .LT. 0.0) then
f=x*x+y*y
else
print (f is undefined)
stop
endif

d)

if ( x .GE. 0.0 .AND .y >=0 ) then


f(x,y) = x + y
else if ( x .GE. 0.0. AND. Y .LT. 0) then
f(x,y) = x + y * y
else if ( x .LT. 0.0 .AND. y .GE. 0) then
f(x,y) = x * x + y
else if ( x .LT. 0.0 .AND. y .LT. 0.0) then
f(x,y) = x * x + y * y
else
print (f is undefined)
stop
endif

e)

All the choices above work well

18) What is the content of the variable M after the


execution?
integer A
real M
A=3
M=A/A/4
a) 0
b) 0.25 c) 0.0 d) 4.0
e) 4
19) What is the content of the variable M after the
execution?
integer A
real M
A=3
M = A / (A / 4.)
a) 0
b) 0.25
c) 0.0
d) 4.0
e) 4
20) What is the content of the variable A after the
execution?
integer A
real M
A=3
A = A / (A / 4.0)
a) 0
b) 0.25 c) 0.0 d) 4.0
e) 4

if ( x .GE. 0.0 .AND. y >=0 ) then


f=x+y
else if ( x .GE. 0.0 .AND. y .LT. 0) then
f=x+y*y
else if ( x .LT. 0.0 .AND. y .GE. 0) then
f=x*x+y
else
f=x*x+y*y
endif

AAAAAAAAAAAAAAAAAAAAAAA
22)What is the FORTRAN equivalent of the
following expression?

a)
a ** ( x + y ) / ( 1.0 + ( -m ) / ( 2 + t * ( 1.0 / ( x + y ) ) )
b)
a ** ( x + y ) / ( 1.0 + ( -m ) / ( 2 + t * ( 1.0 / ( x + y ) ) ) )
c)
a ** ( x + y ) / ( 1.0 + ( -m ) / ( 2 + t * ( 1.0 / ( x + y ) ) ) ) )
d)
a ** ( x + y ) / ( 1.0 + ( -m ) / ( ( 2 + t * ( 1.0 / ( x + y ) ) ) )
e)
a ** ( x + y ) / ( 1.0 + ( -m ) / ( 2 +( t * ( 1.0 / ( x + y ) ) ) )

23) Which operator below has higher precedence in


a FORTRAN expression?
*
/
mod
+
()
1
2
3
4
5
6
a) 1st has the highest precedence
b) 1st and 2nd are the highest and equal precedence
and executed from left to right in an expression.
c) 3rd and 6th are not an operator.
d) 4th and 5th are the highest and equal precedence
and executed from left to right in an expression.
e) 6th has the highest precedence.

AAAAAAAAAAAAAAAAAAAAAAA
26)What is the output of the following program
segment?
integer a, b, c
a=1
b = 10
c = 100
if ( .NOT. ( 3 /= 4 ) ) then
a=2
else if ( 3 .GT. 4 .OR. 5 < 7 - 1 )then
b = 20
else if ( .NOT. ( b /= c/50)) then
c = 200
else
print*, "a=", a
endif
print*, a+b+c
a) 121 b) 111 c) 112

36 / (4 * 2) * 2 * 2 20
a) -2

a) 3.1416

b) 3.1415 c) 3.0

e) Error

c) -4

d) -2.0

e) 0

(3 * 8 / 2 + mod (11, 2) - 1) / 2
b) 6

c) 6.5

d) 23

e) 3

29) What is the result of the below expression?


3 + (7 * 2 - 9) / 2 * 3 - 31 / 2
a) -6

b) 0

c) 37

d) 13

e) -18.5

30) What will be printed by the following


program?
logical a
a= 5<4
print*,a
end
a) 4

d) 3

b) 1.5

28) What is the result of the below expression?

25)What is the output of the following program


segment?
!!!! integer pi
5 format("pi=", f6.4)
pi = 3.14159
write (*,5) pi

e) None of them

27) Find the numerical result for the following


arithmetic operations.

a) 0
24) What will be the output of the program?
integer a
a=1
if (a-1 .LE. 0 .OR. a .GT. 2 .AND. a .GE. a+1) then
a=3
else
a=4
endif
print*, a
end
a) 0
b) 1
c) 2
d) 3
e) 4

d) 211

b) 5

c) T

d) F

e) Error

You might also like