Please use MATLAB!! clear clc %1 Write a for loop that prints out the even numbers from
Fantastic news! We've Found the answer you've been seeking!
Question:
Please use MATLAB!!
clear
clc
%1 Write a for loop that prints out the even numbers from 2 to 20
% (without an if statement - that's next week!)
for i=2:20
fprintf('%d\t,i);
i=i+2;
end
Please help fix this!!
%2 What is this loop's range?
%
Sol26:
To fix the code for problem 1, the fprintf statement is missing a closing single quote and the increment of i should be inside the for loop. Here's the corrected code:
cssCopy codefor
i =
2:
2:
20
fprintf(
'%d\t', i); end
For problem 2, the loop's range is from 2 to 20 with a step size of 2, i.e., it iterates through the even numbers from 2 to 20 inclusive.
Posted Date: