(C ++ / JAVA)ユークリッドアルゴリズム(ユークリッド)は、2つの数の最大公約数、最小公倍数(A * B / MAX)を見つけます

(C ++ / JAVA)ユークリッドアルゴリズム(ユークリッド)2つの数の最大公約数を見つけます。

C ++:

#include<iostream>
using namespace std;
int oujilide(int m, int n)
{
	int r = m%n;
	while (r != 0){
		m = n;
		n = r;
		r = m%n;
	}
	return n;
}
int main(){
	int m, n;
	cin >> m>>n;
	cout << oujilide(m,n);
}

JAVA:

package dm;
/**
 *
 * @author Lenovo
 */
public class DM {
    /**
     * @param args the command line arguments
     */
     public static int oujilide(int m,int n){
        int r=m%n;
        while(r!=0){
            m=n;
            n=r;
            r=m%n;
        }
        return n;
    }
    public static void main(String[] args) {
        System.out.println(oujilide(10,8));
    }
}
リリース5元の記事 ウォンの賞賛4 ビュー572

おすすめ

転載: blog.csdn.net/RY2017_Gaoxusheng/article/details/104126530