--- tags: DICE C --- 6-2 選偶數 === > [name=CHAWTeam] --- 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) 上一篇:[6-1 選正數](https://hackmd.io/@CHAWTeam/DiceC-6-1) 下一篇:[6-3 發現不相等](https://hackmd.io/@CHAWTeam/DiceC-6-3) --- 題目 --- ```! 寫一個程式,輸入一個整數,如果是偶數,印出「(此數)是偶數」;如果不是偶數,則印出「此數」。 以下提供2種範例參考,你的輸出只會是其中一種: 輸入範例1: 78 輸出範例1: 78是偶數 輸入範例2: 9 輸出範例2: 9 ``` ### 提示 ![](https://i.imgur.com/iiGOevp.png) ![](https://i.imgur.com/LD80W7n.png) 程式碼 --- ### 範例1 ```c= #include <stdio.h> int main() { int d, x; scanf("%d", &d); x = d % 2; if (x == 0) //如果輸入的整數可以整除 2 就是偶數 printf("%d是偶數\n", d); if (x == 1) printf("%d\n", d); return 0; } ``` ### 範例2 ```c= #include <stdio.h> int main() { int d; scanf("%d", &d); if ((d % 2) == 0) printf("%d是偶數\n", d); if ((d % 2) == 1) printf("%d\n", d); return 0; } ``` 輸出 --- ```! 78 78是偶數 ``` --- [查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam) 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) 上一篇:[6-1 選正數](https://hackmd.io/@CHAWTeam/DiceC-6-1) 下一篇:[6-3 發現不相等](https://hackmd.io/@CHAWTeam/DiceC-6-3) --- {%hackmd Iiu5mOixR7yWkPHKCkabBg %} <iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-6-2" 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