天天看点

每日一题:第四十九题

第四十九题:输入两个正整数m和n,求其最大公约数和最小公倍数。

每日一题:第四十九题

#include"stdio.h"

void main()

{

    int a,b,t,r,n;

    printf("please input the a and b:\n");

    scanf("%d%d",&a,&b);

    if(a<b)

    {

        t=b;

        b=a;

        a=t;

    }

    r=a%b;

    n=a*b;

    while(r!=0)

    {

        a=b;

        b=r;

        r=a%b;

    }

    printf("这两个数的最大公约数为%d,最小公倍数为%d\n",b,n/b);

继续阅读