MATLAB Answers

write a matlab code that generate a random number, then divide the generated number by 4 if its even number and greater than 100.

4 views (last 30 days)
Ali Salih
Ali Salih on 3 Jul 2020
Commented: Ali Salih on 3 Jul 2020
write a matlab code that generate a random number, then divide the generated number by 4 if its even number and greater than 100.

  4 Comments

Show 1 older comment
Ali Salih
Ali Salih on 3 Jul 2020
x=round(rand()*1000);
disp(['the random number is :' num2str(x)])
if x>100
if rem(x,2)==0
y=x/4;
disp(['the random number is even and greater than 100, answer is :' num2str(y)])
else
disp('the random number is greater than 100 but not even number')
end
else
disp('the random number is not greater than 100')
end

Sign in to comment.

Answers (1)

KSSV
KSSV on 3 Jul 2020
  1. To generate randomnumber read about randi.
  2. To check whether even or not use mod. Read about mod.
  3. To check whether greater or not, read about inequalitites.

  11 Comments

Show 8 older comments

Sign in to comment.