Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started