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

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

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章