6-2 選偶數

CHAWTeam


目錄:DICE C語言程式破解
上一篇:6-1 選正數
下一篇:6-3 發現不相等


題目

寫一個程式,輸入一個整數,如果是偶數,印出「(此數)是偶數」;如果不是偶數,則印出「此數」。

以下提供2種範例參考,你的輸出只會是其中一種:

輸入範例1:
78
輸出範例1:
78是偶數

輸入範例2:
9
輸出範例2:
9

提示

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

程式碼

範例1

#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

#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上的所有筆記
目錄:DICE C語言程式破解
上一篇:6-1 選正數
下一篇:6-3 發現不相等


👉【幫我們一個忙!】👈

👋如果您喜歡這篇文章,請在下方按5個Like!
❤您的支持是我們最大的動力!

您只要登入帳號(Facebook、Google),在下方按5個Like,我們就會收到來自LikeCoin基金會的贊助。
您只需要支持我們,完全不會花到錢!