辗转相除法 最大公因数 + 最小公倍数

//辗转相除法 最大公因数 + 最小公倍数
#include<stdio.h>
void yinshu(int a,int b){
    int temp;
    while(a % b != 0){
        temp = a;
        a = b;
        b = temp % b;
    }
    printf("%d\n",b);
}
void beishu(int a,int b){
    int a1 =a;
    int b1 = b;
    int t;
    while(a%b != 0){
        t = a;
        a= b;
        b = t % b;
    }
    printf("%d",a1/b*b1);
}
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    yinshu(a,b);
    beishu(a,b);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/expedition/p/12005739.html
今日推荐