You are on page 1of 4

# 90 Minutes

28.04.2015 17:40

## CENG 200 Midterm Exam

There are 40 questions (each 2.5 points) for a total of 100 points.
Exam Type:
All questions are multiple choice, no points will be lost for wrong answers.
Assume that all necessary libraries were added properly (by using "include" statements).
Default return type of the main function is int. Assume that the statement return 0; is added to programs if necessary.

Name:

Student ID:

Section:

a) ab.c

b) abc

## 7) What will be printed by the following segment?

c) cb.a

d) bc.a

a) (a**c)**b
b) (a**b)**c
c) (c**b)**a
d) a**(c**b)
e) a**(b**c)
3) Given the contents of the variables:

a) 3.000 3.0
d) 3.000 ***

## What is the result of the following expression:

.NOT.k.eqv.m.and.a>b
1

c) .f. d) .TRUE.

e) .YES.

write(*,10)57.388,55555
format(f5.2,/,i3)
end

b)57.39/

***

***

c)57.38
***

d) 57.388
555

e) 57.39
555

real x; integer y
y=9.9; y=x
print*,y; end
b) 9

b) 14.0

c)10.0

e) 2.8

d)5.0

## 10) What will be printed by the following code?

c) 9.0 d) 10

e) Unknown/Undefined

i=1; j=5
if(j>6.and.i+1>0) then
i=i+1; print*,"A"; else
print*,"B"; end if
if(j>0.or.i+1>0) then
i=i+1; print*,"C"; else
print*,"D"; end if
print*,i
end
b) BC2

a=7/5
if(a-1/=0)then; print*,10*a
else if(a==(a+1)/4)then; print*,2*a
else; print*,5*a; end if; end
a) 2.0

## 6) What is the output of the following program?

a) B
C
2

b) .3E+01 .30E+01 3
d) ****** ******* 3

## 5) What is the output produced by the following program?

a) 10.0

c) ***** 3

isum=17; icount=5
x=isum/icount;
write(*,1)x,x,isum/icount
format(e6.3,1x,e7.2,1x,1i2)
end

a) .3E+1 .30+E1 3
c) ****** .30E+01 3
e) .3e+1 ******* 3

a) 57.39

b) 3.000 3
e) 3.000 3.4

## a=1.0, b=5.0, k=.true., m=.false.

10

isum=17; icount=5
x=isum/icount;
write(*,1)x,isum/icount
format(f5.3,1x,i2)

e) ba.c

## 2) a**b**c is equivalent to:

a) *T* b) .FALSE.

Signature:

c) A

K=5/2
if(K)1,2,3
1
K=K+1; goto(1,2,3),K
2
K=K+2; goto(2,3),K
3
print*,K; end

a) 2.5

b) 2

c) 3

d) 4

e) 4.5

## 11) What is the output of the following code?

d) B
C
3

e) A
C
3

K=5/2
goto(1,2,3),K
1
K=K+1; if(K)1,2,3
2
K=K+2; if(K)1,2,3
3
print*,K; end

a) 4.5

b) 2

c) 2.5

d) 3

e) 4

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
18) Which of the following if statements is doing the action
that is verbally specified as:
if a is smaller than b then c is assigned the value of a,
otherwise c is assigned the value of b

K=5/2
goto(1,2,3),K
K=K+1; goto 4
K=K+1; goto 4
print*,K; end

4
1
2
3
a) 3.5

b) 3

c) 2

d) 2.5

a) if
b) if
c) if
d) if
e) if

e) 4

## 13) What will be displayed by the following code?

m=1; s=5
if(m<100)then
s=s+m; m=m+50; go to 5
else
print*,s,m; stop
end if; end

a) 57.0
101
d) 56.0

b) 57.0
101

100
e) 56

## 19) What will be printed by the following statements?

integer :: m=6,n=3,t=2,k
real :: x=12.72,y=16.0,a,b,c,d
a=y/n+m;
b=m*n; k=x/m; c=m/n; d=n/t
write(*,5)a,b,c,d,k
5 format(4f6.2,i3)

c) 57
102

101

## 14) Assuming a,b,c are integer variables, consider the

operation described in English as:
if a or b is less than c then print OK, otherwise print NO.
Which of the following Fortran Statements perform this
operation?
I. if((a.OR.b)<c)then
II.
Print*,"OK"
Else
Print*,"NO"
endif
III. If(a<c.or.b.LT.c)then
print*,"OK"
else
print*,"NO"
endif

a) 11.33 18.00
b) 12.00 18.00
c) 11
18
d) 11
18
e) 12.00 18.00

a) OK
OK

c)8

a) FALSE

d) 5

e)9

10

d) 45.26

## 17) What is the output of he following code?

integer :: a=5,b=4,c=7,d
d=1.5
print*,mod(c/(a+2),b*d)
end

a) 1

b) 2

c) 4

OK

FAIL

d) FAIL

e) Compile-time Error

FAIL

d) 6

b) .TRUE. c) 4HTRUE

d) 5HFALSE

e) TRUE

## (22) How many times TAKA TUKA printed as an output of the

following code?

integer result
a=4.5255; b=10.0
result=a*b
print*,result
end

c) 45.0

b) FAIL c) OK

i=10; j=0
if(i.EQ.20.OR.j-1/=0)then
print*,4HTRUE
else
print*,5HFALSE
end if
end

b) 45

2
1.5
2
1
2

## integer, parameter :: z=7+3

integer a
a=z/2
print*,a; end

a) 45.255

1.00
2.00
2
2
2.00

real :: a=1.0
if(3<2.OR.3<4.AND.5>6)then
print*,'OK'; else; print*,'FAIL'; endif
if(.NOT.5>6.AND.(a/=2.0))then
print*,'OK'; else; print*,'FAIL'; endif
end

if(c.GT.(a,b))then
print*,"OK"
else
print*,"NO"
endif

b)5.0

2.00
2.00
2.12
2.12
2.00

a) Only I
b) Only II
c) Only III
d) I and III
e) II and III

a) 8.0

## (.not.(a.LT.b)) then; c=b; else; c=a

(a < b)then; c==b; else; c==a
(a <b )c=a, else c=b
(a < b)then c=a; otherwise c=b
(a < b)c=a; c=b

e) 46

i=-5000
i=i+1
if(i.NE.0)then
if(.NOT.mod(i,3).EQ.1)goto 10
print*,'TAKA TUKA'
i=i+1
if(i>10)STOP
goto 10
end if
end

a) 0 times
b) 7 times
c) 10 times
d) 5000 times
e) infinitely many times

e) 8

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
a) 4
b) 4.0
c) 0.0 d) 0 e) Run-time Error
29) What is the output of the following Fortran Program?

## 23) What is the output of the following program?

a) 1
2
3

d) 1
2
3

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
20
b) 1
20
c) 1
6
2
6
2
3
3
3
3
4
1
6.6
3.3
3

integer x; x=2
if(x.eq.3)then; y=1
if(x.le.3)y=2; else; y=3
print*,y; endif
print*,y
end

a) 1.0

b) 3.0

1.0
20
6.66
3

c) 2.0

2.0

d) 3.0

2.0

e) 2.0

3.0

3.0

## 30) How many times CEng200 is printed?

index=0
10 index=index+1
if(index<5)then; goto 15
else;
stop; end if
print*,'CEng200'
15 if(index.LE.10)goto 10
End

e) No output

## 24) What is printed by the following program?

11
51
21
41
61

a) aaa

a) 0 times
b) 10 times
c) 5 times
d) 4 times
e) Infinitely many times

x=3.0
if(x-4.0) 11,21,11
if(x-3) 41,51,41
print*,"a"; goto 61
print*,"aa"; goto 61
print*,"aaa"
stop
end

b) aa

c) a

d) a aaa

## 31) What is the output of the following program

if the input is 60?

e) aa aaa

## 25) What is the content of the variable x after the execution of

the following fragment?
integer a; real x
a=3.0
x=a/(a/4)

a) 4

b) 0.0

c) 4.0

k=0;
k=k+1
if(k<3)then
if(mod(i,3).ne.0.and.mod(i,5).eq.0)then
print*,"A"; else
if(mod(i,3).ne.0.and.mod(i,2).eq.0)then
print*,"B"; else
print*,"C"; end if; end if; end if; end

a) A

d) Error

e) 0

c) 4.0

d) 4

e) Runtime Error

## 27) What is the content of the variable x after the execution of

the following fragment?
integer a; real x
a=3.0
x=a/(a/4.0)

a) Run-time Error

b) 0.0

c) 4

e) C

a) A

b) B

c) C

d) C

e) C

## 33) What is the content of the integer variable M after the

execution of the expression below?
M = 7.0/2 + (5/2.0)!= 100 + 20/10**3

d) 0

e) 4.0

## 28) What is the content of the variable a after the execution of

the following fragment?
integer a; real x
a=3.0
a=a/(a/4.0)
print*,a
end

d) C

k=0;
k=k+1
if(k<3)then
if(mod(i,3).ne.0.and.mod(i,5).eq.0)then
print*,"A"; else
if(mod(i,3).ne.0.or.mod(i,2).eq.0)then
print*,"B"; else
print*,"C"; end if; end if; end if; end

integer a; real x
a=3.0
x=a/a/4

b) 0.0

c) C

## 32) What is the output of the following program

if the input is 60?

## 26) What is the content of the variable x after the execution of

the following fragment?

a) 0

b) B

a) 6

b) 5

c) 6.0

d) 5.0

e) .FALSE.

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
34)What is the output of he following code?
kk=25; ii=15
10 if(ii.GT.kk)stop
if(mod(ii,2).EQ.0)then
kk=kk/3
else; if (mod(ii,3).eq.0)then
kk=kk/2
else; kk=kk*2
endif; endif
print*,ii,kk
ii=ii+2; goto 10
end

a) 15

12.5

d)17

b) 15

12

24.0

e)15.0

c)17

## 38) Which of the following declarations are wrong and cause

compile time errors?
I.
II.
III.
IV.

a) Only IV
d) I and III

a) A

c) C

c) I,II,IV
e) None of them

## 39) What is printed by the following program?

a=3.0
if(a-4)100,200,100
if(a-3)400,500,400
print*,'A'; goto 600
print*,'B'; goto 600
print*,'C'
stop; end

b) B

b) I and IV

24

12.0

implicit none
real
:: m=5
integer :: x=7.5
T=m*x
K=m+x
print*,m,x,T,K
end

## 35) What will be printed by the following program?

100
500
200
400
600

integer :: a=1.0
real :: i=2
real :: c=3
character :: d='CEng200'

d) AB

e) AC

a) 5
7.5 37.5
12.5
b) 5.0 7
35.0
12
c) 5
7.5 35.0
12
d) 5
7.5 35
12.0
e) Compile-Time error

## 36) What is the output of the following program?

40) Which code computes the kth partial sum of the continued
fraction Sk=1+1/Sk-1

integer A , B
A=1; B=2
a=2.5; b=3.2
x=A+b
y=a+B
z=B*(a+b)
print*,x,y,z
end

a) 5.0
c) 4.0
e) 4

5.0
4.0
4

15.0
11.0
11

I)

s=1; i=1
5 s=1+1/s
if(i.le.k-1)goto 5
...
5 s=1+1/s
print*,s

d) 5
5
15

## 37) What is the output of the following program

if the inputs are 75 and -34?

a) Only I
d) Only III

if(ix>0)then
if(iy>0)then
print*,1
else
print*,4; endif
else if(ix<0)then
if(iy>0) then
print*,2
else
print*,3
endif
else
print*,0
endif
end

a) 0

b) 1

c) 2

d) 3

e) 4

b) I and II
e) Only II