C# 辗转相除法求最大公因数和最小公倍数


C# 使用辗转相除法计算两数的最大公因数及最小公倍数

using System;

namespace Program
{
static class Program
{
static int Main(string[] args)
{
int x = 42, y = 12;
while (x!=y)
{
if (x>y)
{
x = x - y;
}
else
{
y = y - x;
}
}
Console.WriteLine("最大公因数是{0},最小公倍数是{1}",x,42*12/y);
Console.ReadLine();
return (0);
}
}
}