辗转相除法

代码:

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int gcd(int a, int b){
    int t;
    while(b!=0){
        t = a%b;
        a = b;
        b = t;
    }
    return a;
} 

int main(int argc, char *argv[]) {
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d,%d最大公约数:%d
",a,b,gcd(a,b));
    printf("%d,%d最小公倍数:%d",a,b,a*b/gcd(a,b));
    return 0;
}

运行结果:

原文地址:https://www.cnblogs.com/ZZG-GANGAN/p/14669941.html