--- tags: DICE C --- 17-8 互質 === > [name=CHAWTeam] --- 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) --- 題目 -- ```! 輸入兩個整數,判斷兩數是否為互質(除了1之外,無共同因數)。 若是互質,則印出「()與()兩數互質」; 否則印出「()與()兩數不互質」。 輸入範例: 24 35 輸出範例: 24與35兩數互質 ``` 程式碼 -- ```c= #include <stdio.h> int main() { int a, b; scanf("%d %d", &a, &b); bool coprime = true; for (int i = 2; a >= i && b >= i; i++) { if (!(a % i) && !(b % i)) { coprime = false; } } if (coprime == true) printf("%d與%d兩數互質", a, b); else printf("%d與%d兩數不互質", a, b); return 0; } ``` 執行 -- ### 輸入 ```! 24 35 ``` ### 輸出 ```! 24與35兩數互質 ``` --- [查看我們在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-17-8" 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