Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Design Operation And Evaluation Of Mobile Communications

Authors: Gavriel Salvendy ,June Wei

1st Edition

3030770249, 978-3030770242

Students also viewed these Programming questions

Question

Differentiate 3sin(9x+2x)

Answered: 1 week ago

Question

Compute the derivative f(x)=(x-a)(x-b)

Answered: 1 week ago