输入年月日判断这是一年的第几天

bool Year_int(int year) //判断这一年是闰年或者不是闰年
{
return (year % 4 == 0 || year % 100!= 0 && year % 400 == 0);
}
int month_day(int year,int month,int day) //利用数组记录每个月相加的天数
{
int ar[] = { 0,31,59,90,120,151,181,212,243,273,304,334,365 };
int num=0;
if (Year_int(year) == 0)
{
num = ar[month-1] + day;
}
else
{
if (month < 3)
{
num = ar[month-1]+day;
}
else
{
num = ar[month-1] + day + 1;
}
}
return num;
}
int main()
{
int year=0, month=0, day=0;
scanf_s("%d,%d,%d", &year, &month, &day);
int num_day = month_day(year, month, day);
printf(“今天是一年中的第%d天”, num_day);
return 0;
}

你可能感兴趣的:(c语言,c语言)