フィルターのクリア

Help me with my function of odd or even!

3 ビュー (過去 30 日間)
Anthony Fuentes
Anthony Fuentes 2016 年 10 月 17 日
回答済み: Anthony Fuentes 2016 年 10 月 18 日
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

採用された回答

Walter Roberson
Walter Roberson 2016 年 10 月 17 日
v = 'el número entrado no es un entero positivo';

その他の回答 (2 件)

KSSV
KSSV 2016 年 10 月 17 日
編集済み: KSSV 2016 年 10 月 17 日
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 2016 年 10 月 18 日
Thanks a lot!

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by