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

Write a program that asks the user to enter an integer x. The program looks at t

ID: 1716219 • Letter: W

Question

Write a program that asks the user to enter an integer x. The program looks at the number and does the following:

- If it is negative, treat it as a positive value and continue with the following steps

- If it is in the range 0 <= x < 10, output whether the number is even or odd

- If it is in the range 10 <= x < 20, output the value of x%10

- If it is in the range 20 <= x < 30, output the value of x%20

- If it is in the range 30 <= x < 40, output the value of x%30

- If it is in the range 40 <= x < 50, output the value of x%40

- If it is in the range x >= 50, output whether it is even or odd and x%50

Explanation / Answer

MATLAB code:

ip=input('Enter the value of x: ');
x=abs(ip);
m=mod(x,2);
if m == 0
    r='EVEN';
else
    r='ODD';
end
if x>=0 && x<10
    disp(r)
elseif x>=10 && x<20
    disp(x*10/100)
elseif x>=10 && x<20
    disp(x*10/100)
elseif x>=20 && x<30
    disp(x*20/100)
elseif x>=30 && x<40
    disp(x*30/100)
elseif x>=40 && x<50
    disp(x*40/100)
elseif x>=50
    disp(r)
    disp(x*50/100)
end

result:

Enter the value of x: 55

ODD
   27.5000

Enter the value of x: 77
ODD
   38.5000

Enter the value of x: 40
    16

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote