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

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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!