輾轉相除求最小公倍數

輾轉相除求最小公倍數

/***************************************************************
*Name            :MinimumCommonMultiple
*Fun             :求最小公倍數
*InputParaments  :m,n是待求的數
*OutputParaments :所求的最小公倍數
****************************************************************/
int MinimumCommonMultiple(int m, int n) {
	int mod1;
	int m0 = m, n0 = n;
	if (m < n) {
		SwapInt(&m,&n);
	}
	do {
		mod1 = m%n;
		m = mod1;
		if (m < n) {
			SwapInt(&m,&n);
		}
	} while (mod1!=0);
	return m0*n0/m;
}
發佈了34 篇原創文章 · 獲贊 47 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章