要求
编写输入某年某月某日,判断这一天是这一年的第几天的程序
代码
#include<stdio.h>
int main()
{
int y,m,d;
int total=0;
scanf("%d年%d月%d日",&y,&m,&d);
if(y%100==0)
{
if(y/100%4==0)
{
switch(m){
case 1:
total = d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 2:
total = 31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 3:
total = 31+29+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 4:
total = 31+29+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 5:
total = 31+29+31+30+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 6:
total = 31+29+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 7:
total = 31+29+31+30+31+30+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 8:
total = 31+29+31+30+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 9:
total = 31+29+31+30+31+30+31+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 10:
total = 31+29+31+30+31+30+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 11:
total = 31+29+31+30+31+30+31+30+31+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 12:
total = 31+29+31+30+31+30+31+30+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
}
}
else
{
switch(m){
case 1:
total = d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 2:
total = 31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 3:
total = 31+28+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 4:
total = 31+28+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 5:
total = 31+28+31+30+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 6:
total = 31+28+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 7:
total = 31+28+31+30+31+30+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 8:
total = 31+28+31+30+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 9:
total = 31+28+31+30+31+30+31+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 10:
total = 31+28+31+30+31+30+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 11:
total = 31+28+31+30+31+30+31+30+31+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 12:
total = 31+28+31+30+31+30+31+30+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
}
}
}
else if(y%4==0)
{
switch(m){
case 1:
total = d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 2:
total = 31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 3:
total = 31+29+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 4:
total = 31+29+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 5:
total = 31+29+31+30+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 6:
total = 31+29+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 7:
total = 31+29+31+30+31+30+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 8:
total = 31+29+31+30+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 9:
total = 31+29+31+30+31+30+31+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 10:
total = 31+29+31+30+31+30+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 11:
total = 31+29+31+30+31+30+31+30+31+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 12:
total = 31+29+31+30+31+30+31+30+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
}
}
else
{
switch(m){
case 1:
total = d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 2:
total = 31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 3:
total = 31+28+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 4:
total = 31+28+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 5:
total = 31+28+31+30+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 6:
total = 31+28+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 7:
total = 31+28+31+30+31+30+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 8:
total = 31+28+31+30+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 9:
total = 31+28+31+30+31+30+31+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 10:
total = 31+28+31+30+31+30+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 11:
total = 31+28+31+30+31+30+31+30+31+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
case 12:
total = 31+28+31+30+31+30+31+30+31+30+31+d;
printf("%d年%d月%d日是这一年的第%d天",y,m,d,total);
break;
}
}
return 0;
}
测试
测试输入
2022年3月5日
输出
2022年3月5日是这一年的第64天