#if 0
#include<stdio.h>
//输入一个日期,判断这个日期是所在年的第几天
int findDate(int year,int mouth,int day)
{
bool IsleapYear = false;
int days = day;
int leapYear[12] = {31,30,31,30,31,30,31,31,30,31,30,31}; //闰年12个月的天数
int commonYear[12] = {31,29,31,30,31,30,31,31,30,31,30,31}; //平年12个月的天数
if(year<=0||mouth<=0||mouth>12||day<=0||day>31)
return 0;
if((year%400 == 0)||(year%4 == 0 &&year%100 !=0)) //判断是否是闰年
IsleapYear = true;
for(int i = 0;i<mouth-1;i++)
{
if(IsleapYear)
{
days+=leapYear[i];
}
else
days+=commonYear[i];
}
return days;
}
int main()
{
int day = findDate(2017,2,14);
printf("%d\n",day);
}
#endif
输入一个日期,输出这个日期是所在年的第几天
最新推荐文章于 2024-09-10 21:03:26 发布