C语言分别求两个整数的最大公约数和最小公倍数

#include <stdlib.h>
#include <math.h>
#include <stdio.h>
//递归算法
//欧几里得算法
void GCD(int a, int b)
{
    int temp;
    temp = a % b;
    if(a % b)
    {
        GCD(b,temp);
    }
    else
        printf("%d ",b);


}
//穷举法
void LCM(int a, int b)
{
int i;


for(i = 1;;i++)
    if(i%a ==0&&i%b==0)
break;
   printf("%d",i);


}


int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    GCD(a,b);
    LCM(a,b);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/u012345982/article/details/80247348