#include <stdio.h> int GCD(int a,int b); int LCM(int a,int b); int main() { int num1,num2,gcd,lcm; //printf("求两个数的最大公约数及最小公倍数 请输入你想计算的两个数: "); scanf("%d%d",&num1,&num2); //gcd=GCD(num1,num2); lcm=LCM(num1,num2); printf("%d ",lcm); } int GCD(int a,int b) { if ( a % b == 0) { return b; } else return GCD( b,a % b) ; } int LCM(int a,int b) { int temp_lcm; temp_lcm=a*b/GCD(a,b); //最小公倍数等于两数之积除以最大公约数 return temp_lcm; }
计算两数之最小公倍数