help me solve this if statement

1 visualizzazione (ultimi 30 giorni)
MALLA VENKATA HARI NARAYANA SUBUDHI
Modificato: Alan Stevens il 18 Mag 2021
could you help me solve this?
]
number = randi([0,9])
if number == 2 ||4 ||6||8
disp('number is even')
elseif number == 1||3||5||7||9
disp('number is odd')
else
disp('number is zero')
end

Risposte (1)

Alan Stevens
Alan Stevens il 18 Mag 2021
Modificato: Alan Stevens il 18 Mag 2021
Remove the ] in the top line!
Then
number = randi([0,9])
evens = [2,4,6,8];
odds = [1,3,5,7,9];
if ismember(number,evens)
disp('number is even')
elseif ismember(number,odds)
disp('number is odd')
else
disp('number is zero')
end

Categorie

Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by