Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part A. Write a Matlab program with a conditional (while) loop that prints out a

ID: 3590101 • Letter: P

Question

Part A. Write a Matlab program with a conditional (while) loop that prints out all the multiples of 3 between 0 and 20, inclusive.

Part B. Write a Matlab program with a counting (for) loop that prints out all the multiples of 3 between 0 and 20, inclusive. You will find this is slightly shorter than the method in problem 3. Typically, it's easier to count (even by some non-unit increment) using counting loops.

Part C. Write a Matlab program that prompts the user for an integer value between 1 and 10, inclusive. Use a loop (your choice of which kind) to print out all of the integers between 1 (not 0) and 100, inclusive, that are multiples of that number.

Explanation / Answer

%a

i=1;
while(i<=20)
if mod(i,3)==0
disp(i)
end
i=i+1;
end

%b

i=1;
for i=1:20
if mod(i,3)==0
disp(i)
end
end

%c
n=input('Enter n:');
for i=1:100
if mod(i,n)==0
disp(i)
end
end