#include<stdio.h>
int main()
{
int year,month,day;
scanf("%d %d",&year,&month);
switch(month)
{
case 2:
if (year % 4 == 0 && year % 100 != 0)
day = 29;
else
day = 28;
break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
day = 31;
break;
case 4:
case 6:
case 9:
case 11:
day = 30;
break;
default:
break;
}
printf("%d年%d月有%d天",year,month,day);
return 0;
}
10输入某年某月某日,转化成某年的第几天输出。
#include<stdio.h>
int main()
{
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int Year,Month,Day,i,days=0;
printf("请按照年月日的顺序输入日期:");
scanf("%d %d %d",&Year,&Month,&Day);
if(Year%4 == 0&&Year%100!=0)
a[2]+=1;
for(i=1;i<=Month-1;i++)
days+=a[i];
days+=Day;
printf("%d年%d月%d日是%d年的第%d天!\n",Year,Month,Day,Year,days);
return 0;
}