C语言问题:键盘输入年月日,输出,该日是该年的第几天

键盘输入年月日,输出,该日是该年的第几天
2024-12-01 09:45:41
推荐回答(1个)
回答1:

通过编译了的以下是代码:
#include
void main()
{
int year,month,day;
scanf("%d,%d,%d",&year,&month,&day);
if((year%4==0&&year%100!=0)||(year%400==0))
switch(month)
{
case 1:printf("the day is %d\n",day);break;
case 2:printf("the day is %d\n",31+day);break;
case 3:printf("the day is %d\n",60+day);break;
case 4:printf("the day is %d\n",91+day);break;
case 5:printf("the day is %d\n",121+day);break;
case 6:printf("the day is %d\n",152+day);break;
case 7:printf("the day is %d\n",182+day);break;
case 8:printf("the day is %d\n",213+day);break;
case 9:printf("the day is %d\n",244+day);break;
case 10:printf("the day is %d\n",274+day);break;
case 11:printf("the day is %d\n",305+day);break;
case 12:printf("the day is %d\n",335+day);break;
default:printf("bad input\n");
}
else
switch(month)
{
case 1:printf("the day is %d\n",day);break;
case 2:printf("the day is %d\n",31+day);break;
case 3:printf("the day is %d\n",59+day);break;
case 4:printf("the day is %d\n",90+day);break;
case 5:printf("the day is %d\n",120+day);break;
case 6:printf("the day is %d\n",151+day);break;
case 7:printf("the day is %d\n",181+day);break;
case 8:printf("the day is %d\n",212+day);break;
case 9:printf("the day is %d\n",243+day);break;
case 10:printf("the day is %d\n",273+day);break;
case 11:printf("the day is %d\n",304+day);break;
case 12:printf("the day is %d\n",334+day);break;
default:printf("bad input\n");
}
}