1.count = 0 ; 2.array1 = randi ( [ 0 100 ],10 ,10 ); 3. for ii = 1 : 10 4. for j
ID: 3588202 • Letter: 1
Question
1.count = 0;
2.array1 = randi( [0 100],10 ,10 );
3.for ii = 1:10
4. for jj = 1:10
5. break;
6. count ___
7. if array1( ____ ) > 20
8. disp(array1 ( ____ );
9. end
10. end
11.end
1)Inside the inner loop (jj), what need to go in the parenthesis such that every array element in array1 is tested and possibly displayed?
a.n
b.jj
c.ii
d.ii, jj
2)On line 6, how would we increment count by 1 each time so that by the end it will display how many times the loop iterated?
a.+1
b.= count + 1
c.= 1
d.= result + count + 1
3)What will the value of count be when the loops are finished executing?
a.0
b.10
c.100
d.1
Explanation / Answer
1)
array1 is a 2D array. So, to access any element we need to pass 2 arguements. Hence, answer is d. ii, jj.
All other options are single arguements which can't access element in a 2D array.
2)
(a) +1 would make line 6 as ' count + 1 ' which is invalid statement .
(b) = count + 1 would make line 6 as ' count = count + 1 ' which is valid statement as count is incremented by 1 and saved in count itself.
(c) This option will only set count to 1 each time.
(d) result is not defined, so it will show compile time error.
Answer is (b).
3)
Both loops run 10 times each. Hence, count = 10 * 10 = 100.
Answer = (c)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.