Using MATLAB: Create a nested for-loop script to iterate through all values of i
ID: 3145164 • Letter: U
Question
Using MATLAB: Create a nested for-loop script to iterate through all values of i=1:12 and j=1:12. Also start with a running tally of total=0. At each iteration, check the value of j. If j is divisible by 4, then do nothing and proceed to the next value of j using the continue method. Next, if i*j is divisible by 5, then stop processing the current j-based for-loop using the break method, and move on to the next value of i. If both conditions have not been met, then add both i and j to the running tally called total. What is your final value for total at the end of your script?
Explanation / Answer
total=0;
for i=1:12
for j=1:12
if mod(j,4)==0
continue;
end
if mod(i*j,5)==0
break;
end;
total=total+i+j;
end
end
%Print
total
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.