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