--- tags: DICE C --- 14-9 自主學習 === > [name=CHAWTeam] --- 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) --- 題目 --- ```! 請撰寫一程式, 輸入一個數字,輸出該小於等於該數字的所有合數。 合數是除了1和其本身外具有其他正因數的正整數。 依照定義,每一個大於1的整數若不是質數,就會是合數。 1不是質數也不是合數。 輸入範例: 10 輸出範例: 4 6 8 9 10 ``` 程式碼 --- ```c= #include <stdio.h> int main() { int n; scanf("%d", &n); for (int i = 2; i <= n; i++) { for (int j=2; j < i; j++) { if (i % j == 0) { printf("%d\n", i); break; } } } } ``` 執行 --- ### 輸入 ```! 10 ``` ### 輸出 ```! 4 6 8 9 10 ``` --- [查看我們在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-9" 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