计算最大公因数的欧几里德算法

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

int gcd(int m, int n)
{
    int rem;
    while(n > 0)
    {   
        rem = m % n;
        m = n;
        n = rem;
    }   
    return m;
}

int main()
{
    int m, n;
    printf("Please input two numbers: \n");
    scanf("%d %d", &m, &n);
    if(m > n)
        printf("the max gcd of the two number is: %d\n", gcd(m,n));
    else
        printf("the max gcd of the two number is: %d\n", gcd(n,m));
    return 0;
}

你可能感兴趣的:(计算最大公因数的欧几里德算法)