--- tags: DICE C --- 8-1 奇數還是偶數? === > [name=CHAWTeam] --- 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) 上一篇:[7-4 判斷閏年](https://hackmd.io/@CHAWTeam/DiceC-7-4) 下一篇:[8_2 是否能構成三角形?](https://hackmd.io/@CHAWTeam/DiceC-8_2) --- 題目 --- ```! 寫一個程式,輸入一個整數, 如果是偶數,印出「(此數)是偶數」; 如果是奇數,則印出「(此數)是奇數」。 以下提供 2 種範例參考,你的輸出只會是其中一種: 輸入範例1: 78 輸出範例1: 78是偶數 輸入範例2: 45 輸出範例2: 45是奇數 範例程式: #include <stdio.h> #include <stdlib.h> int main() { int num;/*宣告整數變數*/ scanf("...",...);/*輸入整數變數*/ if(......){/*判斷n的餘數是否為0*/ printf("......\n",......); } else{/*二分法*/ printf("......\n",......); } return 0; } ``` ### 提示 ![](https://i.imgur.com/e9etgBR.png) 程式碼 --- ```c= #include <stdio.h> int main() { int x; scanf("%d", &x); if (x % 2 == 0) printf("%d是偶數\n", x); else printf("%d是奇數\n", x); return 0; } ``` 輸出 --- ```! 78 78是偶數 ``` ```! 45 45是奇數 ``` --- [查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam) 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) 上一篇:[7-4 判斷閏年](https://hackmd.io/@CHAWTeam/DiceC-7-4) 下一篇:[8_2 是否能構成三角形?](https://hackmd.io/@CHAWTeam/DiceC-8_2) --- {%hackmd Iiu5mOixR7yWkPHKCkabBg %} <iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-8-1" 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