练习-用switch语句实现输入某年某月某日,判断这一天是这一年的第几天
时间: 2023-11-20 08:50:01 浏览: 264
java 输入某年某月某日,判断这一天是这一年的第几天
可以参考以下代码实现:
```c
#include <stdio.h>
int main() {
int year, month, day, sum = 0;
printf("请输入年月日,格式为yyyy-mm-dd:");
scanf("%d-%d-%d", &year, &month, &day);
switch (month) {
case 12: sum += 30;
case 11: sum += 31;
case 10: sum += 30;
case 9: sum += 31;
case 8: sum += 31;
case 7: sum += 30;
case 6: sum += 31;
case 5: sum += 30;
case 4: sum += 31;
case 3:
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
sum += 29;
} else {
sum += 28;
}
case 2: sum += 31;
case 1: sum += day;
}
printf("%d年%d月%d日是这一年的第%d天\n", year, month, day, sum);
return 0;
}
```
阅读全文