how do you write function divisible(n)?

10 ビュー (過去 30 日間)
John locke
John locke 2014 年 3 月 4 日
回答済み: David Sanchez 2014 年 3 月 4 日
The function has one parameter n. If n is divisible by both 3 and 5, the function returns true. Otherwise returns false.

採用された回答

Chandrasekhar
Chandrasekhar 2014 年 3 月 4 日
function [Res] = divisible(n)
if(rem(n,3)==0 && rem(n,5) == 0)
Res = 1;
else
Res = 0;
end

その他の回答 (1 件)

David Sanchez
David Sanchez 2014 年 3 月 4 日
Re-using the code above, you can do it in a single line:
function [Res] = divisible(n)
Res = (rem(n,3)==0 && rem(n,5) == 0);

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by