필터 지우기
필터 지우기

how do you write function divisible(n)?

조회 수: 18 (최근 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 CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by