#include <stdio.h>
void main()
{
printf("请输入年月日\n");
int a,b,c,d;
scanf("%d%d%d",&a,&b,&c);
switch(b)
{
case 12:d=c+31;
case 11:d=c+30;
case 10:d=c+31;
case 9:d=c+30;
case 8:d=c+31;
case 7:d=c+31;
case 6:d=c+30;
case 5:d=c+31;
case 4:d=c+30;
case 3:d=c+31;
case 2:if(a%4==0&&a%100!=0||a%400==0)
d=c+29;
else
d=c+28;
case 1:d=c;
}
printf("为%d年的第%d天",a,d);
}
这样?
这样!
#include
int main()
{
printf("请输入年月日\n");
int a,b,c,d=0; //d给初值0
scanf("%d%d%d",&a,&b,&c);
switch(b)
{
case 12:d +=30; //加上上月的天数
case 11:d +=31;
case 10:d +=30;
case 9:d +=31;
case 8:d +=31;
case 7:d +=30;
case 6:d +=31;
case 5:d +=30;
case 4:d +=31;
case 3:
if( ( a%4==0&&a%100!=0) ||(a%400==0) )
d+=29;
else
d+=28;
case 2:d +=31;
case 1:d+=c;
}
printf("为%d年的第%d天\n",a,d);
return 0;
}