2025-03-06 22:45:14 +08:00

32 lines
718 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*-------------------------------------------------------
输入一个年月日要求输出这一天是该年的第几天。例如2000年3月2日是该年的第62天
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i, year,month,day,days;
days=0;
printf("请输入一年日期格式为yyyy-mm-dd");
scanf("%d-%d-%d",&year,&month,&day);
for(i=1;i<month;i++)
{
switch(i)
{
/**********Program**********/
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:days+=31;break;
case 2: days+=28;days += (year%4==0&&year%100!=0||year%400==0)?1:0;break;
default:
days+=30;
/********** End **********/ }
}
days=days+day;
printf("%d-%d-%d是这一年中的第%d天\n",year,month,day,days);
}