Skip to content

Instantly share code, notes, and snippets.

@aminzai
Created November 9, 2012 17:35
Show Gist options
  • Save aminzai/4047027 to your computer and use it in GitHub Desktop.
Save aminzai/4047027 to your computer and use it in GitHub Desktop.
Test1
測試環境Dev-C++ 4.9.9.2
GCD Function有點問題
1.遞迴的Function應該都要有return去接,要不然在某些Compiler 就算沒有下return也可過,如果要直接抓值的話,預設正常執行完function的回傳值就是0,所以會出現0的數值算是正常運算。
2.第二判斷的判斷值錯了。
int gcd(int n1,int n2){
if (n1 > n2){
return gcd(n1-n2,n2);
} else if (n1 < n2){ <===這裡判斷反了
return gcd(n2-n1,n1);
}else{
return n1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment