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

THIS IS A MATLAB QUESTION - PROGRAMMING LANGUAGE, YOU ARE TO WRITE A MATLAB CODE

ID: 3914384 • Letter: T

Question

THIS IS A MATLAB QUESTION - PROGRAMMING LANGUAGE, YOU ARE TO WRITE A MATLAB CODE BASED ON REQUIREMENTS BELOW:

In-class Exercise 1. Complete the following tasks using if statements a) Generate a single random number between 1 and 100. Use an if statement to check if the value is greater than 50. If so display the number, else display nothing b) Ask a user to input a number between 5 and 10. Display a message that states whether or not the input number was within the required range c) Ask a user to input two numbers, one between 20 and 25, the second between 50 and 55. Display a message that states if both inputs were correct, if only one input was correct, or if neither inputs were correct.

Explanation / Answer

a) Code:  

x = input('input a number between 1 to 100');

if (x>50)

disp(x)

else

fprintf('nothing');

end

b)code:

x=input('input a no. between 5 to 10'');

if(x>=5 & x<=10)

fprintf('the input is in correct range');

else

fprintf('the input is not in correct range');

end

c)

x=input('enter first number');

y=input('enter second number');

if(x>20 & x<25)

if (y>50 & y<55)

fprintf('boths inputs are correct')

else

fprintf('first input is correct and second input is wrong');

end

else

if (y>50 & y<55)

fprintf('first input is wrong and Second input is right');

end

end