#include<stdio.h>
bool Is_Leap(int year)
{
return(year % 4 == 0 && year % 100 != 0 || (year % 400 == 0);//判断是不是闰年
}
int YearMonth_To_Day(int year, int month)
{
int day[] = {29,31,28,31,30,31,30,31,31,30,31,30,31};
if (month == 2 && Is_Leap(year))//注意二月有两个数据
{
month = 0;
}
return day[month];
}
int Get_YMD_To_Total(int year, int month, int day)
{
int total = 0;
int i = 1;
if (year < 1) return -1;
if (month < 1 || month > 12) return -2;
if (day < 1 || day > YearMonth_To_Day(year, month)) return -3;
for (int i = 1; i < month; ++i)
{
total += yearMonth_To_Day(year, i);
}
return total + day;
}
int main()
{
int year = 0, month = 0, day = 0, total = 0;
scanf_s("%d%d%d",&year, &month, &day);
total = Get_YMD_To_Total(year, month, day);
if (total > 0)
{
printf("%d year %d month %d day => total \n", year, month, day, total);
}
else
{
printf("input error \n");
}
return 0;
}
计算某年某月某日是这一年的第几天
最新推荐文章于 2024-11-14 19:30:39 发布