(C ++ / JAVA) Euclidean algorithm (Euclidean) find greatest common divisor of two numbers, the least common multiple (A * B / MAX)

(C ++ / JAVA) Euclidean algorithm (Euclidean) find greatest common divisor of two numbers

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));
    }
}
Released five original articles · won praise 4 · Views 572

Guess you like

Origin blog.csdn.net/RY2017_Gaoxusheng/article/details/104126530