--- tags: DICE C --- 9-3 玩玩二分法 === > [name=CHAWTeam] 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) 題目 --- ```! 寫一個程式來判斷你給的數,落在什麼區域? 如果是正數,首先印出「(此數)是正數」, 小於等於10000,則顯示「A」; 其餘正數,則顯示「B」。 負數,則印出「(此數)是負數」, 小於等於-10000,則顯示「C」; 其餘負數,則顯示「D」。 因為此題輸出有多種狀況,故需將程式碼複製3次,都判斷正確才給分,每個輸出都要換行。 以下提供 2 種範例參考,你的輸出只會是其中一種: 輸入範例1: 6000 輸出範例1: 6000是正數 A 輸入範例2: -99 輸出範例2: -99是負數 D ``` 程式碼 --- ```c= #include <stdio.h> int main() { int a; scanf("%d", &a); if (a > 0) { printf("%d是正數\n", a); if (a <= 10000) printf("A\n"); else printf("B\n"); } if (a < 0) { printf("%d是負數\n", a); if (a <= -10000) printf("C\n"); else printf("D\n"); } scanf("%d", &a); if (a > 0) { printf("%d是正數\n", a); if (a <= 10000) printf("A\n"); else printf("B\n"); } if (a < 0) { printf("%d是負數\n", a); if (a <= -10000) printf("C\n"); else printf("D\n"); } scanf("%d", &a); if (a > 0) { printf("%d是正數\n", a); if (a <= 10000) printf("A\n"); else printf("B\n"); } if (a < 0) { printf("%d是負數\n", a); if (a <= -10000) printf("C\n"); else printf("D\n"); } return 0; } ``` 輸出 --- ```! 6000 6000是正數 A -99 -99是負數 D 4000 4000是正數 A ``` --- [查看我們在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-9-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