Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a = [1 2 3 4 5; 2 3 4 5 6; 3 2 3 3 3; 5 6 7 8 9]; [n, m] = size(a); c=0; d =0; f

ID: 3924504 • Letter: A

Question

a = [1 2 3 4 5; 2 3 4 5 6; 3 2 3 3 3; 5 6 7 8 9]; [n, m] = size(a); c=0; d =0; for i = 1:n for j = 1:m if a(i, j)==2 c = c+1; end if a(i, j)>=8 d= d+1; end end end e = c*d; f = c/d; What will be the values of c, d, e and f after execution of the script. Write a output code line at the end of the script using fprintf to appropriately display c, d, e, and f and their values. How would you modify the code using if/elseif combination and obtain the same result. Explain how the modification changes the program execution.

Explanation / Answer

The number of 2's in the matrix is stored in c and the number of values greater than 8 is stored in d. So c will be 3 and d will be 2.

e = 6 and f = 1.5

The line for printing is

Changing to elseif:

if a(i,j)==2

c = c+1;

elseif a(i,j)>=8

d = d+1

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote