#define _CRT_SECURE_NO_WARNINGS
//⽅法1
#include <stdio.h>
int main()
{
int m = 0;
int n = 0;
scanf("%d %d", &m, &n);
//计算m和n的较⼤值
//m和n的最⼩公倍数,最⼩也是m和n中较⼤的值
int k = (m > n ? m : n);
//重复对k进⾏判断
while (1)
{
//若k被两数同时整除,则k为公倍数,并且此时⼀定是最⼩公倍数 if (k % m == 0 && k % n == 0)
{
printf("%d\n", k);
break;
}
//k的值加⼀,对下⼀个数进⾏判断
k++;
}
return 0;
}
//⽅法2
#include <stdio.h>
int main()
{
int m = 0;
int n = 0;
//输⼊
scanf("%d %d", &m, &n);//18 24
int k = 0;
int mul = m * n;
//辗转相除法求得最⼤公约数
while (k = m % n)
{
m = n;
n = k;
}
printf("%d\n", mul / n);
return 0;
}
题目描述:
输入2个整数m和n,计算m和n的最小公倍数,并打印出结果