张赐荣——一位视障程序员。
赐荣小站: www.prc.cx

張賜榮

张赐荣的技术博客

博客园 首页 新随笔 联系 订阅 管理

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);
}
}
}
posted on 2022-03-21 19:46  张赐荣  阅读(234)  评论(0编辑  收藏  举报

感谢访问张赐荣的技术分享博客!
博客地址:https://cnblogs.com/netlog/
知乎主页:https://www.zhihu.com/people/tzujung-chang
个人网站:https://prc.cx/