-->
当前位置:首页 > 题库 > 正文内容

程序填空题:输出每个月的天数

Luz4年前 (2021-05-10)题库4871
输入年,输出该年每个月的天数。其中1、3、5、7、8、10、12月有31天,4、6、9、11月有30天,2月平年有28天,闰年有29天。判断闰年的条件是:能被 4 整除但不能被 100 整除,或者能被 400 整除。
```c++
#include

int main()
{
int day, month, year;

scanf("%d", &year);
for(month = 1; month <= 12; month++){
switch @@[( month )](1){
case 2:
if@@[((year % 4 == 0 && year % 100 != 0)||year % 400 == 0 )](1) {
day = 29;
}else{
@@[day = 28; ](1)
}
@@[break;](1)
@@[case 1: case 3: case 5: case 7: case 8: case 10: case 12:](1)
day = 31; break;
@@[case 4: case 6: case 9: case 11: ](1)
day = 30; break;
}
printf("%d ", day) ;
}

return 0;
}

```






答案:
第1空:( month )

第2空:((year % 4 == 0 && year % 100 != 0)||year % 400 == 0 )

第3空:day = 28;

第4空:break;

第5空:case 1: case 3: case 5: case 7: case 8: case 10: case 12:

第6空:case 4: case 6: case 9: case 11:

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。