Write a function called holiday that takes two input arguments called month and day; both are scalar integers representing a month (1-12) and a day (1-31). You do not need to check that the input is valid. The function returns a logical true if the s
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
function [v] = holiday(day,month)
a=[1,1];
b=[4,7];
c=[25,12];
d=[31,12];
A= [day,month]
if A == a | A == b | A == c |A == d
v= true
else
v=false
end
here i'm getting an error with input(7,4) . any idea why? the format for the code being(day,month) is adhered to.
0 commentaires
Réponses (5)
Stephan
le 6 Juin 2018
Modifié(e) : Stephan
le 6 Juin 2018
Hi,
Your condtion is A = [4,7] --> you tried [7,4]:
function [v] = holiday(day,month)
a=[1,1];
b=[4,7];
c=[25,12];
d=[31,12];
A = [day,month]
if A == a | A == b | A == c |A == d
v= true;
else
v=false;
end
v
check for x = holiday(4,7):
x = holiday(4,7)
v =
logical
1
x =
logical
1
check for y = holiday(7,4):
y = holiday(7,4)
v =
logical
0
y =
logical
0
Best regards
Stephan
Arrah Calvin
le 30 Juil 2018
Modifié(e) : Stephen23
le 30 Juil 2018
Here is my take on the problem. I've tested it, and it works. I don't know why your function doesn't work while it looks like it should.
function [v] = holiday(month,day)
a=[1,1];
b=[7,4];
c=[12,25];
d=[12,31];
A = [month,day];
if A == a
v=true;
elseif A == b
v=true;
elseif A == c
v=true;
elseif A == d
v=true;
else
v=false;
end
0 commentaires
Duddela Sai Prashanth
le 23 Sep 2018
%Simplest one - Tested
function value = holiday(month,day)
if month == 1 && day == 1
value = true;
elseif month == 7 && day == 4
value = true;
elseif month == 12 && (day == 25 || day == 31)
value = true;
else
value = false;
end
0 commentaires
Akshatha Gangappa
le 17 Oct 2018
function [v] = holiday(m,d) if (( m==1 && d ==1) (m==7 && d ==4) (m==12 && d ==25)||(m ==12 && d== 31)) v = true; else v = false; end end
0 commentaires
muhammad usman
le 5 Avr 2020
function H = holiday(month,day);
if (month == 1 && day == 1) || (month == 7 && day ==4) || (month == 12 && day == 25) || (month == 12 && day == 31);
H = true;
else fprintf(' go to work\n '); H = false;
end
0 commentaires
Voir également
Catégories
En savoir plus sur Calendar dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!