您的位置:首页 > 其它

机试算法讲解: 第23题 哦,最小公倍数

2015-07-31 00:35 274 查看
/*
关键:最小公倍数 = 两数乘积/最大公约数
*/

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

//求最大公约数
int gcd(int a,int b)
{
	if(b==0)//关键:默认b!=0,因为取模的时候b不能为0
	{
		return a;
	}
	else
	{
		return gcd(b,a%b);//其他情况用递归
	}
}

int main(int argc,char* argv[])
{
	int a,b;
	while(EOF!=scanf("%d %d",&a,&b))
	{
		int iGCD = gcd(a,b);
		printf("%d",a*b/iGCD);
	}
	system("pause");
	getchar();
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: