2025-03-06 23:47:59 +08:00

28 lines
744 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.

/*-------------------------------------------------------
功能编写程序使用Switch ),给出年月日,计算出该日是该年的第几天。判断是否为
闰年的条件是:能被 4 整除但是不能被100整除或者能被四百整除。
--------------------------------------------------------*/
#include"stdio.h"
main()
{
int year,month,day,days=0,i,d;
printf("请输入年-月-日:");
scanf("%d-%d-%d",&year,&month,&day);
for(i=1;i<month;i++)
{
/**********Program**********/
switch(i){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10: days+=31;break;
case 2: days+=(28 + (year%4==0&&year%100!=0 || year%400==0?1:0));break;
default: days+=30;
}
/********** End **********/
}
printf("%d-%d-%d是该年第%d天\n",year,month,day,days + day);
}