how do you write function divisible(n)?

26 visualizaciones (últimos 30 días)
John locke
John locke el 4 de Mzo. de 2014
Respondida: David Sanchez el 4 de Mzo. de 2014
The function has one parameter n. If n is divisible by both 3 and 5, the function returns true. Otherwise returns false.

Respuesta aceptada

Chandrasekhar
Chandrasekhar el 4 de Mzo. de 2014
function [Res] = divisible(n)
if(rem(n,3)==0 && rem(n,5) == 0)
Res = 1;
else
Res = 0;
end

Más respuestas (1)

David Sanchez
David Sanchez el 4 de Mzo. de 2014
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);

Categorías

Más información sobre Encryption / Cryptography en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by