gcd函數的書寫方式有很多種,很多人都是用循環的,而小編的模闆用則是用函數的遞歸,從代碼上很簡介,且非常易于了解。
#include<stdio.h>//最小公倍數
int gcd(int a,int b)
{
return b==0? a:gcd(b,a%b);
}
int main()
{
int m,n;
while(scanf("%d %d",&m,&n)!=EOF)
{
printf("%d\n",m*n/gcd(m,n));
}
return 0;
}