算法——最大公因子

/* 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\n", 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;
}

 

posted @ 2019-09-09 11:25  no樂on  阅读(443)  评论(0编辑  收藏  举报