2025-03-06 12:46:40 +08:00

35 lines
689 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.

/*-------------------------------------------------------
任意输入一个日期,计算这一天是这一年中的第几天(考虑闰年和平年)。
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int y,m,d,s,f;
s=0;
printf("请输入一个日期YYYY-MM-DD");
scanf("%d-%d-%d",&y,&m,&d);
if(y%4==0&&y%100!=0||y%400==0)
f=1;
else
f=0;
switch(m-1)
{
/**********Program**********/
case 11: s+=30;
case 10: s+=31;
case 9: s+=30;
case 8: s+=31;
case 7: s+=31;
case 6: s+=30;
case 5: s+=31;
case 4: s+=30;
case 3: s+=31;
case 2: s+=f+28;
case 1: s+=31;
/********** End **********/
}
s=s+d ;
printf("%d-%d-%d是这一年中的第%d天\n",y,m,d,s);
}