求最大公約數

求最大公約數
/*
歐幾里得法求最大公約數
除數當被除數
餘數當除數
直到餘數爲0,返回除數
*/
public class gcd {
    public static int gcd1(int m,int n){
        while(n!=0){
            int r=m%n;
            m=n;
            n=r;
        }
        return m;
    }
}
發佈了39 篇原創文章 · 獲贊 31 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章