输入两个正整数m和n,求其最大公约数和最小公倍数

/输入两个正整数m和n,求其最大公约数和最小公倍数。/

#include <stdio.h>
int gcd(int a, int b)
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return gcd(b, a % b);
    }
}
int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}
int main(void)
{
    int m, n;
    printf("please enter number m and n\n");
    scanf("%d %d", &m, &n);
    int greatest_common_divisor = gcd(m, n);
    int least_common_multiple = lcm(m, n);
    printf("The greatest common divisor is:%d\n", greatest_common_divisor);
    printf("The least common multiple is:%d\n", least_common_multiple);
    return 0;
}

posted on 2024-07-09 23:36  wessf  阅读(76)  评论(0)    收藏  举报