Create a script using If statements

2 vues (au cours des 30 derniers jours)
Allyson
Allyson le 28 Fév 2014
Réponse apportée : ES le 28 Fév 2014
We ask someone to input a number then,
If the user enters an even number (tell by using mod)
• if the number is less than ten print out “Your number is less than 10”
• if the number is greater than ten print out “Your number is greater than 10”
• if the number is equal to ten print out “Your number equals 10”
I am not sure how to check to see if it is an even number, and if it is, how to write the rest.
  1 commentaire
per isakson
per isakson le 28 Fév 2014
Modifié(e) : per isakson le 28 Fév 2014
What does the documentation on mod say?

Connectez-vous pour commenter.

Réponses (1)

ES
ES le 28 Fév 2014
x=input('Input your number')
if mod(x,2)==0
disp('Even Number');
else
disp('Odd Number');
end

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by