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 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 on 3 Jul 2020
no,I need code of this quetions
madhan ravi on 3 Jul 2020
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 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
Ali Salih on 3 Jul 2020
where is the divide by 4
KSSV on 3 Jul 2020
If you want it you can include it..
Ali Salih on 3 Jul 2020
ok, tanks a lot

Sign in to comment.