c语言用函数求最大公倍数和最小公约数

c语言用函数求最大公倍数和最小公约数
#include<stdio.h>
#include<math.h>
#include<string.h>
#include
using namespace std;
int main()
{
int a,b;
scanf("%d%d",&a,&b);
int c=__gcd(a,b);
printf("%d\n",c);//求出最大公约数
int d=a*b;//推理可知最小公倍数是两个数乘积除于最大公约数
int e=d/c;
printf("%d\n",e);//求出最小公倍数
return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43846139/article/details/84591509
今日推荐