能被4整除且不能被100整除的为闰年。如2004年就是闰年,1900年不是闰年。世纪年能被400整除的是闰年,如2000年是闰年,1900年不是闰年。对于数值很大的年份,这年如果能被3200整除,并且能被172800整除则是闰年。如172800年是闰年,86400年不是闰年,因为虽然能被3200整除,但不能被172800整除。
1、地球绕太阳运行周期为365天5小时48分46秒(合365.24219天),即一回归年(tropical year)。公历的平年只有365日,比回归年短约0.2422 日,每四年累积约一天,把这一天加于2月末(即2月29日),使当年时间长度变为366日(1-12月分别为31天,29天,31天,30天,31天,30天,31天,31天,30天,31天,30天,31天),这一年就为闰年。
2、闰年(Leap Year)是为了弥补因人为历法规定造成的年度天数与地球实际公转周期的时间差而设立的。补上时间差的年份为闰年。闰年共有366天(1-12月分别为31天,29天,31天,30天,31天,30天,31天,31天,30天,31天,30天,31天)。
3、凡阳历中有闰日(二月为二十九日)的年;闰余(岁余置闰。阴历每年与回归年相比所差的时日);注意闰年(公历中名词)和闰月(农历中名词)并没有直接的关联,公历中只分闰年和平年,平年有365天,而闰年有366天(2月中多一天);平年中也可能有闰月(如2017年是平年,农历有闰月,闰6月)。
#include
#include
int main()
{
int year,month,day,runnian,dday;
printf("请输入年,月,日(中间用逗号隔开):\n");
scanf("%d,%d,%d",&year,&month,&day);
if(year%100==0)
{
if(year%400==0)
{
runnian=1;
printf("%d是闰年",year);
}
else
{
runnian=0;
printf("%d不是闰年",year);
}
}
else{
if(year%4==0)
{
runnian=1;
printf("%d是闰年\n",year);
}
else
{
runnian=0;
printf("%d不是闰年\n",year);
}
}
if(runnian==1)
{
switch(month){
case 1:
dday=day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 2:
dday=31+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 3:
dday=31+29+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 4:
dday = 31+29+31+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 5:
dday = 31+29+31+30+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 6:
dday = 31+29+31+30+31+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 7:
dday = 31+29+31+30+31+30+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 8:
dday = 31+29+31+30+31+30+31+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 9:
dday = 31+29+31+30+31+30+31+31+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 10:
dday = 31+29+31+30+31+30+31+31+30+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 11:
dday = 31+29+31+30+31+30+31+31+30+31+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 12:
dday = 31+29+31+30+31+30+31+31+30+31+30+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
}
}
else{
switch(month){
case 1:
dday=day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 2:
dday=31+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 3:
dday=31+28+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 4:
dday = 31+28+31+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 5:
dday = 31+28+31+30+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 6:
dday = 31+28+31+30+31+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 7:
dday = 31+28+31+30+31+30+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 8:
dday = 31+28+31+30+31+30+31+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 9:
dday = 31+28+31+30+31+30+31+31+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 10:
dday = 31+28+31+30+31+30+31+31+30+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 11:
dday = 31+28+31+30+31+30+31+31+30+31+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
case 12:
dday = 31+28+31+30+31+30+31+31+30+31+30+day;
printf("%d年%d月%d日是这年的第%d天",year,month,day,dday);
break;
}
}
}
自己写的,所以代码不够简洁!