How do I answer this question?

1 回表示 (過去 30 日間)
Jawel wardeh
Jawel wardeh 2021 年 6 月 14 日
回答済み: Shelly Choudhary 2021 年 6 月 15 日
Display the multiple of 9 from 1 through 100

回答 (2 件)

Matt J
Matt J 2021 年 6 月 14 日

Shelly Choudhary
Shelly Choudhary 2021 年 6 月 15 日
Hi Jawel,
There are many ways to approach this question in MATLAB:
Method 1:
% Initialize a vector with numbers 1 to 100
>> a = 1:100;
% Keep only those values which give remainder = 0 when divided by 9
>> a(mod(a, 9) == 0
Method 2:
% Use the function a : b : c which returns numbers starting from a till c, incrementing in a gap of b
>> a = 9 : 9 : 100
Method 3:
% calculate the maximum number of multiples of 9 smaller than 100 as: total_multiples = floor(100 / 9) and store them
>> a = 1 : total_multiples;
% use .* operator to multiply each element of a by 9
>> a = 9 .* a
Hope this helps!

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by