youngchou1997
2016-05-27 22:16:09浏览 9306
#include <stdio.h>
int february_day_num(int year_num);
int main()
{
/* 定义需要计算的日期 */
int year = 2008;
//需计算的年
int month = 8;
//需计算的月
int day = 8;
//需计算的日
int february;
int num;
/*使用switch来判断月对应天数*/
switch(month)
{
case 1: num=day; break;
case 2: num=31+day; break;
case 3: num=31+day;break;
case 4: num=31*2+day;break;
case 5: num=31*2+30+day;break;
case 6: num=31*3+30+day;break;
case 7: num=31*3+30*2+day;break;
case 8: num=31*4+30*2+day;break;
case 9: num=31*5+30*2+day;break;
case 10: num=31*5+30*3+day;break;
case 11: num=31*6+30*3+day;break;
case 12: num=31*6+30*4+day;break;
default: printf("一年是十二个月哦。");break;
}
/*二月的天数*/
february = february_day_num(year);
if(year>2)
{
num += february;
}
printf("%d年%d月%d日是该年的第%d天", year, month, day, num);
return 0;
}
/*二月的天数判断*/
int february_day_num(int year_num)
{
if(year_num%4==0||year_num%400==0)
{
if(year_num%100!=0)
{
year_num = 29;
}
}
else
{
year_num = 28;
}
return year_num;
}
热门评论
上面的方法判断错了吧。试试2000年看看
if((year%4==0&&year%100!=0)||(year%400==0))