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.
  4 件のコメント
Ali Salih
Ali Salih 2020 年 7 月 3 日
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

サインインしてコメントする。

回答 (2 件)

KSSV
KSSV 2020 年 7 月 3 日
  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 件のコメント
KSSV
KSSV 2020 年 7 月 3 日
If you want it you can include it..

サインインしてコメントする。


Sysy Gdhhdys
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) ')'])
the random number that is between 100 and 1000 is ( 825)
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
the number is greater than 500
the number is odd

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by