算法——最大公因子

/* maxCommonFactor.c */
/* 最大公因子数 */

#include <stdio.h>

int maxCommonFactor(int m, int n);

int main(){
    int m, n;

    printf("Enter two integers: ");
    scanf("%d %d", &m, &n);
    printf("max common factor: %d
", maxCommonFactor(m, n));
    
    return 0;
}

int maxCommonFactor(int m, int n){
    int r = m % n;
    while(r != 0){
        m = n;
        n = r;
        r = m % n;
    }
    return n;
}
原文地址:https://www.cnblogs.com/noonjuan/p/11490640.html