---
tags: DICE C
---
11-3 月份判斷
===
> [name=CHAWTeam]
---
目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC)
上一篇:[11-3 薪資計算](https://hackmd.io/@CHAWTeam/DiceC-11-3)
下一篇:[11-5 三角形型別](https://hackmd.io/@CHAWTeam/DiceC-11-5)
---
題目
---
```!
寫一個程式讓使用者輸入月份,印出該月份所屬季節:
12-2月:輸出「(月份)是冬天」
3-5月:輸出「(月份)是春天」
6-8月:輸出「(月份)是夏天」
9-11月:輸出「(月份)是秋天」
13以上則輸出「(數字)超出範圍」
因為此題輸出有多種狀況,故需將程式碼複製3次,都判斷正確才給分,每個輸出都要換行。
輸入範例:
6
10
15
輸出範例:
6月是夏天
10月是秋天
超出範圍
```
程式碼
---
```c=
#include <stdio.h>
int main()
{
int x;
scanf("%d", &x);
if (x == 12 || x <= 2)
printf("%d月是冬天\n", x);
else if (x >= 3 && x <= 5)
printf("%d月是春天\n", x);
else if (x >= 6 && x <= 8)
printf("%d月是夏天\n", x);
else if (x >= 9 && x <= 11)
printf("%d月是秋天\n", x);
else
printf("超出範圍\n");
scanf("%d", &x);
if (x == 12 || x <= 2)
printf("%d月是冬天\n", x);
else if (x >= 3 && x <= 5)
printf("%d月是春天\n", x);
else if (x >= 6 && x <= 8)
printf("%d月是夏天\n", x);
else if (x >= 9 && x <= 11)
printf("%d月是秋天\n", x);
else
printf("超出範圍\n");
scanf("%d", &x);
if (x == 12 || x <= 2)
printf("%d月是冬天\n", x);
else if (x >= 3 && x <= 5)
printf("%d月是春天\n", x);
else if (x >= 6 && x <= 8)
printf("%d月是夏天\n", x);
else if (x >= 9 && x <= 11)
printf("%d月是秋天\n", x);
else
printf("超出範圍\n");
return 0;
}
```
輸出
---
```!
6
6月是夏天
10
10月是秋天
15
15超出範圍
```
---
[查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam)
目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC)
上一篇:[11-3 薪資計算](https://hackmd.io/@CHAWTeam/DiceC-11-3)
下一篇:[11-5 三角形型別](https://hackmd.io/@CHAWTeam/DiceC-11-5)
---
{%hackmd Iiu5mOixR7yWkPHKCkabBg %}
<iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-11-3" width="100%"></iframe>
---
{%hackmd i1nMRrZcTFmTvoF897K9zg %}