题目:输入某年某月某日,判断这一天是这一年的第几天?
#include<stdio.h>
int main()
{
int year, month, day;
scanf("%d,%d,%d", &year, &month, &day);
int cnt = 0;
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
{
switch (month)
{
case 1:
cnt = day;
break;
case 2:
cnt = 31 + day;
break;
case 3:
cnt = 31 + 29 + day;
break;
case 4:
cnt = 31 + 29 + 31 + day;
break;
case 5:
cnt = 31 + 29 + 31 + 30 + day;
break;
case 6:
cnt = 31 + 29 + 31 + 30 + 31 + day;
break;
case 7:
cnt = 31 + 29 + 31 + 30 + 31 + 30 + day;
break;
case 8:
cnt = 31 + 29 + 31 + 30 + 31 + 30 + 31 + day;
break;
case 9:
cnt = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + day;
break;
case 10:
cnt = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;
break;
case 11:
cnt = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;
break;
case 12:
cnt = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;
break;
}
}
else
{
switch (month)
{
case 1:
cnt = day;
break;
case 2:
cnt = 31 + day;
break;
case 3:
cnt = 31 + 28 + day;
break;
case 4:
cnt = 31 + 28 + 31 + day;
break;
case 5:
cnt = 31 + 28 + 31 + 30 + day;
break;
case 6:
cnt = 31 + 28 + 31 + 30 + 31 + day;
break;
case 7:
cnt = 31 + 28 + 31 + 30 + 31 + 30 + day;
break;
case 8:
cnt = 31 + 28 + 31 + 30 + 31 + 30 + 31 + day;
break;
case 9:
cnt = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + day;
break;
case 10:
cnt = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;
break;
case 11:
cnt = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;
break;
case 12:
cnt = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;
break;
}
}
printf("这一天是这一年的第%d天", cnt);
return 0;
}