--- tags: DICE C --- 13-3 月份判斷 === > [name=CHAWTeam] --- 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) --- 題目 --- ```! 寫一個程式讓使用者輸入月份,印出該月份所屬季節; 12-2月是冬天 3-5月是春天 6-8月是夏天 9-11月是秋天 13以上則顯示,則超出範圍 程序需可重複輸入月份,直到輸入月份小於等於0為止。 輸入範例: 6 1 5 13 -100 輸出範例: 6月是夏天 1月是冬天 5月是春天 超出範圍 ``` 程式碼 --- ```c= #include <stdio.h> int main() { int x; scanf("%d", &x); repeat: if (x == 12 || x == 2 || x == 1) 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 >= 0) goto repeat; return 0; } ``` 輸出 --- ```! 6 6月是夏天 1 1月是冬天 5 5月是春天 13 超出範圍 -100 ``` --- [查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam) 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) --- {%hackmd Iiu5mOixR7yWkPHKCkabBg %} <iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-13-3" width="100%"></iframe> --- {%hackmd i1nMRrZcTFmTvoF897K9zg %}
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up