matlab小程序

输入一个日期,输出是第几天

year=input('year : ')
month=input('month : ')
day=input('day : ')

year1=[31,28,31,30,31,30,31,31,30,31,30,31];
year2=[31,29,31,30,31,30,31,31,30,31,30,31];
%isloopyear=0
if mod(year,4)==0||(mod(year,4)==0 && mod(year,100)~=0)
    isloopyear=1
else
    isloopyear=0
end
sum=0
if isloopyear==1
    for n=1:month-1
        sum=sum+year2(n);
    end
else
    for n=1:month-1
        sum=sum+year1(n);
    end
end
sum=sum+day

标签:Matlab

评论已关闭