--- tags: DICE C --- 14-1 奇數還是偶數? === > [name=CHAWTeam] --- 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) --- **題目 --- ```! 寫一個程式,輸入十個整數, 如果是偶數,印出「(此數)是偶數」; 如果是奇數,則印出「(此數)是奇數」。 輸入範例: (每輸入一筆立即會顯示結果,然後再輸入下一筆) 78 77 100 102 22 42 46 86 90 100 輸出範例: 78是偶數 77是奇數 100是偶數 102是偶數 22是偶數 42是偶數 46是偶數 86是偶數 90是偶數 100是偶數 C範例程式: #include <stdio.h> int main() { int i,num;/*宣告整數變數*/ i=1; while(i<=10){ scanf("%d",&num);/*輸入整數變數*/ if(num%2==0){/*判斷n的餘數是否為0*/ printf("%d是偶數\n",num ); } else{/*二分法*/ printf("%d是奇數\n",num ); } i=i+1; } return 0; } C++範例程式: #include <iostream> using namespace std; int main() { int i,num;/*宣告整數變數*/ i=1; while(i<=10){ cin>>num;/*輸入整數變數*/ if(num%2==0){/*判斷n的餘數是否為0*/ cout<<num<<"是偶數"<<endl; } else{/*二分法*/ cout<<num<<"是奇數"<<endl; } i=i+1; } return 0; } ``` 程式碼 --- ```c= #include <stdio.h> int main() { int x; for (int i = 0; i < 10; i++) { scanf("%d", &x); if (x % 2 == 0) printf("%d是偶數\n", x); else printf("%d是奇數\n", x); } return 0; } ``` 執行 --- ### 輸入 ```! 78 77 100 102 22 42 46 86 90 100 ``` ### 輸出 ```! 78是偶數 77是奇數 100是偶數 102是偶數 22是偶數 42是偶數 46是偶數 86是偶數 90是偶數 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-14-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