help me solve this if statement
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Alan Stevens
2021년 5월 18일
편집: Alan Stevens
2021년 5월 18일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!