
用matlab做:任意输入一个年份,判断是不是闰年,要用switch语句实现,拜托拜托
展开全部
闰年的概念:
普通闰年:能被4整除但不能被100整除的年份。(如2004年就是闰年,1999年不是闰年);
世纪闰年:能被400整除的的年份。(如2000年是闰年,1900年不是闰年);
根据闰年的概念,用matlab的switch语句实现,即任意输入一个年份,判断是不是闰年。
实现方法:
Ly = input('输入任意一个年份,如2018: ');
switch true
case mod(Ly,400)==0
disp('世纪闰年')
case mod(Ly,4)==0 & mod(Ly,400)~=0
disp('普通闰年')
case mod(Ly,4)>0
disp('普通年')
otherwise
disp('输入有误')
end
运行效果
2018-09-22 · 知道合伙人互联网行家
关注

展开全部
#include <iostream>
using namespace std;int main()
{
int year,mounth;
int yk,ym;
cin>>year;
cin>>mounth;
{if((year%4==0)&&(year%100!=0)||(year%400==0)) yk=366; else yk=365; }
if (yk==366)
{ if(mounth==2)
ym=29;
else if(mounth==4||mounth==6||mounth==9||mounth==11) ym=30;
else ym=31;
}
else
{ if(mounth==2)
ym=28;
else if(mounth==4||mounth==6||mounth==9||mounth==11) ym=30;
else ym=31;
}
cout<<"年份"<<" "<<year<<" "<<"天数"<<" "<<yk<<endl;
cout<<"月份"<<" "<<mounth<<" "<<"天数"<<" "<<ym<<endl;
return 0;
using namespace std;int main()
{
int year,mounth;
int yk,ym;
cin>>year;
cin>>mounth;
{if((year%4==0)&&(year%100!=0)||(year%400==0)) yk=366; else yk=365; }
if (yk==366)
{ if(mounth==2)
ym=29;
else if(mounth==4||mounth==6||mounth==9||mounth==11) ym=30;
else ym=31;
}
else
{ if(mounth==2)
ym=28;
else if(mounth==4||mounth==6||mounth==9||mounth==11) ym=30;
else ym=31;
}
cout<<"年份"<<" "<<year<<" "<<"天数"<<" "<<yk<<endl;
cout<<"月份"<<" "<<mounth<<" "<<"天数"<<" "<<ym<<endl;
return 0;
追问
亲,首先谢谢了,可是我是要matlab编写的,switch格式.
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询