--- tags: DICE C --- 23-2 最大公因數 === > [name=CHAWTeam] 目錄:[DICE C語言程式破解](/@CHAWTeam/DiceC) 題目 --- ```! 輸入兩個整數,找出最大公因數。 這是寫過的題目,再用遞迴試試! 輸入範例: 6 18 輸出範例: 6 ``` 程式碼 --- ```c= #include <stdio.h> int gcd(int a, int b) { if (a < b) { gcd(b, a); } if (a == 0) { return b; } else if (b == 0) { return a; } return gcd(b, a % b); } int main() { int a, b; scanf("%d %d", &a, &b); printf("%d", gcd(a, b)); return 0; } ``` 執行 --- ### 輸入 ```! 6 18 ``` ### 輸出 ```! 6 ``` --- [查看我們在HackMD上的所有筆記](/@CHAWTeam) 目錄:[DICE C語言程式破解](/@CHAWTeam/DiceC) --- {%hackmd Iiu5mOixR7yWkPHKCkabBg %} <iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-23-2" 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