COMP 200 Final Exam 2025
Questions and Answers
Consider the following code fragment:
x = 2;
while x < 13
fprintf('We are the music makers, ')
fprintf('and we are the dreamers of dreams.\n')
x = x + 1.6;
end
How many lines of output will display in the Command Window?
a. 8 b. 16 c. 14 d. 7 - ✔✔D
What is an issue with trying to time computer code runs?
a. Run times can vary from run to run, especially if other tasks are competing for time
on the processor.
b. The operating system (OS) can make adjustments to the system clock, so using the
system clock for timing presents difficulties.
c. Both A and B are correct.
COPYRIGHT © 2025 BY OLIVIA WEST, ALL RIGHTS RESERVED 1
,d. None of the above - ✔✔C
n terms of amounts of required storage, how do these data types compare?
a. single < complex number consisting of singles < double
b. single < double < complex number consisting of singles
c. double < complex number consisting of singles = single
d. single < complex number consisting of singles = double - ✔✔D
In MATLAB, which relational operator can be used to check if two variables are not
equal to each other?
a. !=
b. <>
c. ==
d. ~= - ✔✔D
A sparse matrix is a matrix where:
a. The elements are zeros below the diagonal and non-zero above the diagonal.
b. Non-zero elements are confined to a diagonal band comprising the main diagonal,
and it can have zeros or more diagonals on either side of the main diagonal.
c. Most of the elements are zero.
d. Most of the elements are non-zero - ✔✔C
Consider the following code fragment:
x = [1 3 6]; j = 0;
for i = 1:5
COPYRIGHT © 2025 BY OLIVIA WEST, ALL RIGHTS RESERVED 2
, while j < 3
for k = x
% Nothing
end
if j/3 == 0
j = j + 2;
else
j = j + 1;
end
end
end
What will be the value of j at the end of this code fragment?
a. 4 b. 5 c. 3 d. 6 - ✔✔C
Consider the following code fragment:
a = 3;
b = 4;
switch a
case 1
if b > 2
c = 'Red Hot Chili Peppers';
else
COPYRIGHT © 2025 BY OLIVIA WEST, ALL RIGHTS RESERVED 3
Questions and Answers
Consider the following code fragment:
x = 2;
while x < 13
fprintf('We are the music makers, ')
fprintf('and we are the dreamers of dreams.\n')
x = x + 1.6;
end
How many lines of output will display in the Command Window?
a. 8 b. 16 c. 14 d. 7 - ✔✔D
What is an issue with trying to time computer code runs?
a. Run times can vary from run to run, especially if other tasks are competing for time
on the processor.
b. The operating system (OS) can make adjustments to the system clock, so using the
system clock for timing presents difficulties.
c. Both A and B are correct.
COPYRIGHT © 2025 BY OLIVIA WEST, ALL RIGHTS RESERVED 1
,d. None of the above - ✔✔C
n terms of amounts of required storage, how do these data types compare?
a. single < complex number consisting of singles < double
b. single < double < complex number consisting of singles
c. double < complex number consisting of singles = single
d. single < complex number consisting of singles = double - ✔✔D
In MATLAB, which relational operator can be used to check if two variables are not
equal to each other?
a. !=
b. <>
c. ==
d. ~= - ✔✔D
A sparse matrix is a matrix where:
a. The elements are zeros below the diagonal and non-zero above the diagonal.
b. Non-zero elements are confined to a diagonal band comprising the main diagonal,
and it can have zeros or more diagonals on either side of the main diagonal.
c. Most of the elements are zero.
d. Most of the elements are non-zero - ✔✔C
Consider the following code fragment:
x = [1 3 6]; j = 0;
for i = 1:5
COPYRIGHT © 2025 BY OLIVIA WEST, ALL RIGHTS RESERVED 2
, while j < 3
for k = x
% Nothing
end
if j/3 == 0
j = j + 2;
else
j = j + 1;
end
end
end
What will be the value of j at the end of this code fragment?
a. 4 b. 5 c. 3 d. 6 - ✔✔C
Consider the following code fragment:
a = 3;
b = 4;
switch a
case 1
if b > 2
c = 'Red Hot Chili Peppers';
else
COPYRIGHT © 2025 BY OLIVIA WEST, ALL RIGHTS RESERVED 3