最大公约数与最大公倍数

来源:互联网 发布:linux telent 编辑:程序博客网 时间:2024/04/28 11:36

辗转相除法

#include<stdio.h>int main(){    int m, n;    int x, y, temp;    printf("Enter two integer:\n");    scanf("%d %d", &m, &n);    if (m > 0 && n >0)    {        x=m;        y=n;        temp=x%y;        while(temp!=0)        {            x=y;            y=temp;            temp=x%y;        }        printf("Greatest common divisor: %d\n",y);        printf("Lease common multiple : %d\n", m * n /y);    }    else printf("Error!\n");    return 0;}



0 0