how do you write function divisible(n)?
13 次查看(过去 30 天)
显示 更早的评论
The function has one parameter n. If n is divisible by both 3 and 5, the function returns true. Otherwise returns false.
0 个评论
采纳的回答
Chandrasekhar
2014-3-4
function [Res] = divisible(n)
if(rem(n,3)==0 && rem(n,5) == 0)
Res = 1;
else
Res = 0;
end
0 个评论
更多回答(1 个)
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);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!