Borrar filtros
Borrar filtros

Help me with my function of odd or even!

3 visualizaciones (últimos 30 días)
Anthony Fuentes
Anthony Fuentes el 17 de Oct. de 2016
Respondida: Anthony Fuentes el 18 de Oct. de 2016
Hi! I need help with my function. When I put a negative number, matlab gives me an error;
Error using disp
Too many output arguments
This function is about that the user put any number and the function returns a 1 if it is even, a 0 if it is odd or if the number is not a integer an error message. Thanks a lot.
function[v]=dimesiespar2(n)
if rem(n,1) == 0 && n>0
if rem(n, 2)==0
v=1;
else
v=0;
end
else
v= disp('el número entrado no es un entero positivo');
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 17 de Oct. de 2016
v = 'el número entrado no es un entero positivo';

Más respuestas (2)

KSSV
KSSV el 17 de Oct. de 2016
Editada: KSSV el 17 de Oct. de 2016
function[v]=dimesiespar2(n)
if rem(n,1) == 0 && n>0
if rem(n, 2)==0
v=1;
else
v=0;
end
else
disp('el número entrado no es un entero positivo');
end

Anthony Fuentes
Anthony Fuentes el 18 de Oct. de 2016
Thanks a lot!

Categorías

Más información sobre Matrices and Arrays 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