年月日判断
#include<stdio.h>
int main()
{
int year,mouth,day,sum,x;
printf("年月日:");
scanf("%d,%d,%d",&year,&mouth,&day);
switch(mouth)
{
case 1: sum=0;break;
case 2: sum=31;break;
case 3: sum=31+28;break;
case 4: sum=31+28+31;break;
case 5: sum=31+28+31+30;break;
case 6: sum=31+28+31+30+31;break;
case 7: sum=31+28+31+30+31+30;break;
case 8: sum=31+28+31+30+31+30+31;break;
case 9: sum=31+28+31+30+31+30+31+31;break;
case 10:sum=31+28+31+30+31+30+31+31+30;break;
case 11:sum=31+28+31+30+31+30+31+31+30+31;break;
case 12:sum=31+28+31+30+31+30+31+31+30+31+30;break;
default:printf("ERROR!\n");
}
x=sum+day;
if((year%400==0)||(year%4==0&&year%100!=0))
{
printf("%d年是闰年!\n",year);
if(mouth>2)
{
x+=1;
}
}
else printf("%d年不是闰年!\n",year);
printf("%d年%d月%d日是%d年的第%d天!\n",year,mouth,day,year,x);
return 0;
}