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

MATLAB PROBLEM: Write a MATLAB script utilizing an IF-ELSE statement that asks f

ID: 3803845 • Letter: M

Question

MATLAB PROBLEM:

Write a MATLAB script utilizing an IF-ELSE statement that asks for the user to enter a whole number. After the number is entered, the computer must then determine the parity of the number, that is whether the number is an even number or an odd number. If the number is even, MATLAB must then generate and display the message: The entered number is an even number. Otherwise, MATLAB must generate and display the message: The entered number is an odd number.

(Hint: What basic property of numbers makes them odd or even? What existing MATLAB function that we had discussed in class can we take advantage of to determine the parity of numbers?)

Explanation / Answer

in an simple and easy way we can write matlab code for the even odd number as follows


%even odd number
%evenodd.m

b= input ('Enter an integer'); %input a whole number
if rem(b,2) == 0 %if reminder is equal to 0 its and even buddy out their
disp('the number is even number ')
else %else print the odd buddy
disp('the number is odd number ')
end

Thanks happy codeing if not neccessary please remove comments % things from code

Output

Enter an Integer 2

the number is even number