--- tags: DICE C --- 17-7 最大公因數 === > [name=CHAWTeam] --- 目錄:[DICE C++語言程式破解](https://hackmd.io/@CHAWTeam/DiceCpp) --- 題目 -- ```! 請撰寫一程式,輸入二個正整數,找出兩整數的公因數與最大公因數。 格式如輸出範例所示,公因數中間以空格隔開。 輸入範例: 30 60 輸出範例: 30與60的公因數1 2 3 5 6 10 15 30 30與60的最大公因數30 ``` 程式碼 -- ```c= #include <stdio.h> int main() { int a, b, max; scanf("%d %d", &a, &b); printf("%d與%d的公因數", a, b); for (int i = 1; a >= i && b >= i; i++) { if (a % i == 0 && b % i == 0) { printf("%d ", i); max = i; } } printf("\n%d與%d的最大公因數%d\n", a, b, max); return 0; } ``` 輸入 -- ```! 30 60 ``` 輸出 -- ```! 30與60的公因數1 2 3 5 6 10 15 30 30與60的最大公因數30 ``` --- [查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam) 目錄:[DICE C++語言程式破解](https://hackmd.io/@CHAWTeam/DiceCpp) --- {%hackmd Iiu5mOixR7yWkPHKCkabBg %} <iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-17-7" 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