You are on page 1of 2

ENGR 141 Spring 2011 ICA 16, Part I Name: ________________________ Table #___

Question Scratch Work / Code Tracing Answer

A. What value or values are displayed by the following


code?

Q = -5;
fprintf('Q\tN')
for N=3:2:7
fprintf('%.0f\t%.0f',Q,N)
Q=Q+1+N;
end

B. What value or values are displayed by the following


code?

Q = -5;
for N=3:2:7
fprintf('Q\tN')
Q=Q+1+N;
fprintf('%.0f\t%.0f',Q,N)
end

C. What value or values are displayed by the following


code?

V=[20 -8 3 -3 -2 50];
i=1;
j=1;
for x=1:1:length(V)
if V(x) > 0
P(i)=V(x);
i=i+1;
else
N(j)=V(x);
j=j+1;
end
end
disp (P)
disp (N)
ENGR 141 Spring 2011 ICA 16, Part I Name: ________________________ Table #___

Question Scratch Work / Code Tracing Answer

1. What value or values are displayed by the following


code?

for N = 3:2:8
fprintf('%.1f\n',N)
end

2. What value or values are displayed by the following


code?

i = 4;
j = 3;
k = j^2;
for N = i:i/2:k
fprintf('%.2f\n',N)
end

3. How many times will the word roger be printed to the


screen?

for K = 4:-3:-4
fprintf('roger\n')
end

4. What value or values are displayed by the following


code?

for M = 0.5:0.1:0.9
Quack = M;
end
fprintf('%.2f\n',Quack)

5. What value or values are displayed by the following


code?

for K = 5:10:100
if K <= sqrt(300)
fprintf(‘%.0f\n’,K^3)
end
end

You might also like