why not it work between 1 and 10?

clc
num = input('enter a number between 1 and 10:->');
if (num < 1 && num > 10)
disp('invalid number')
else
disp('valid number')
end

4 Comments

num < 1 && num > 10
Can you give us an example of a number that is both less than one AND greater than ten?
no,it's not possible but i want to say that if user input a value which is either less than 1 or greater than 10,then the program show invalid number.
if num < 1 || num > 10
thank u Dennis.

Answers (1)

I think it is unlikely, that one number is smaller than 1 and bigger than 10 at the same time.
num = input('enter a number between 1 and 10:->');
if num > 1 && num < 10
disp('valid number');
else
disp('invalid number')
end

This question is closed.

Tags

Asked:

on 14 Aug 2018

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!