write a matlab code that generate a random number, then divide the generated number by 4 if its even number and greater than 100.
조회 수: 1 (최근 30일)
이전 댓글 표시
write a matlab code that generate a random number, then divide the generated number by 4 if its even number and greater than 100.
답변 (2개)
KSSV
2020년 7월 3일
- To generate randomnumber read about randi.
- To check whether even or not use mod. Read about mod.
- To check whether greater or not, read about inequalitites.
댓글 수: 11
Sysy Gdhhdys
2022년 3월 15일
편집: Walter Roberson
2022년 3월 15일
clc;clear all;
x=randi([100,1000]) ;
disp(['the random number that is between 100 and 1000 is ( ' num2str(x) ')'])
if x>500;
disp('the number is greater than 500')
x2=~mod(x,2);
x3=x2*x;
x4=x3/4;
if x4==0;
disp('the number is odd')
else
disp(['that number is even and greater than 500 we divided by 4 is equal to (' num2str(x4) ')'])
end
else
disp('the number is not greater than 500')
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!