码迷,mamicode.com
首页 > 其他好文 > 详细

两个数的最小公倍数

时间:2015-04-01 00:29:41      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:算法   c   

问题:

         求两个数的最小公倍数

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int m, n, b;
	int temp, k;
	int lcw;
	scanf("%d%d", &m, &n);
	k = m*n;
	if(m<n)
	{
		temp = m;
		m = n;
		n = temp;
	}
	b = m%n;
	while(b)
	{
		m = n;
		n = b;
		b = m%n;
	}
	lcw = k/n;//依照公式: 最小公倍数=两数乘积/最大公约数
	printf("%d\n", lcw); 
	return 0;
}
/*
45 63
315

4 5
20
*/


两个数的最小公倍数

标签:算法   c   

原文地址:http://blog.csdn.net/orangeisnotapple/article/details/44787451

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!