Suppose the following matrix represents the number of saws ordered from your company each month over the last year:
saws=[ 1,4,5,3,7,5,3,10,12,8,7,4]
All the numbers should be zero or positive
a/ Use an if statement to check whether any of the values in the matrix are invalid.(Evaluate the whole matrix at once in a single if statement.) Send a message"All valid" or else "Invalid number found" to the screen, depending on the results of your analysis
b/ Change the saws matrix to include at least one negative number, and check your program to make sure that it works for both cases
Answers
Step-by-step explanation:
function [valid]=valid_date(year, month, day)
if isscalar(year) && year>0 && year~=0 && isscalar(month) && month>0 && month~=0 && isscalar(day) && day>0 && ar
if mod(year,4) == 0 && mod(year, 100)~= 0 || mod(year,400)==0 && month==2 && days<=29
%for february
valid=true;
else
valid=false;
end
%for rest of the months
if month==4 || month==6 || month==9 || month==11 && day<=30
valid=true;
elseif month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month== 12 && day<=31
valid=true;
else
valid=false;
end
%not a leap year
if month==2 && day>28
valid=false;
end
%rest of the months
if month==4 || month==6 || month==9 || month==11 && day<=30
valid=true;
elseif month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month== 12 && day<=31
valid=true;
else
valid=false;
end
else
valid=false;
end