Professional Documents
Culture Documents
ECE105
ECE105 Homework 6
Sections: if/else mistakes; Even or Odd; if/else by hand; while loops by hand
Submission type:
• sections 1-2: pdfs uploaded to Canvas
• sections 3-4: work by hand, take photos/scans of finished work, upload to Canvas
Points: 20
1
Cody Anderson
ECE105
• mod(9,2) 1
• mod(8,2) 0
• mod(8,3) 2
• mod(5.5,1) 0.5
Write a MATLAB script that requests a numeric input from the user (input function) and then
uses an if/else branching statement to write a sentence that states whether the number is
even, odd, or not an integer.
A sample display of successful operation for all three types of outputs is shown below.
Publish the completed script to pdf. It will give an error during publishing due to the input
function—do not worry about this.
2
Cody Anderson
ECE105
a b c
7 9
5 0
-2 1
2 0
3 1
x y z
3 7
3 0
9 2
5 2
5 3
3
Cody Anderson
ECE105
%% Example B
b = 56;
while rem(b,2)==0
b = b/2
end
4
Cody Anderson
ECE105
%% Example D
a = 1;
b = 7;
while a~=b
b = b-1
end
5
Cody Anderson
ECE105
%% Example F
a = 1;
b = 12;
while a~=b
b = b-1
a = a*2
end
% you may need to type
ctrl+c
6
Cody Anderson
ECE105
%% Example H
B = ones(1,5);
ind = 2;
while ind<=length(B)
B(ind) = ind^3;
ind = ind + 2;
end
B