c#设计静态方法求两个数的最大公约数最小公倍数和判断一个整数是否被3整除
c#设计静态方法求两个数的最大公约数最小公倍数和判断一个整数是否被3整除
/// <summary>
/// 求公倍数
/// </summary>
/// <param name="num1"></param>
/// <param name="num2"></param>
/// <returns></returns>
public static int GBS(int num1, int num2)
{
int maxNum = Math.Max(num1, num2);
int result = num1 * num2;
for (int i = maxNum; i <= num1 * num2; i++)
{
if (i % num1 == 0 && i % num2 == 0)
{
result = i;
break;
}
}
return result;
}
/// <summary>
/// 求公约数
/// </summary>
/// <param name="num1"></param>
/// <param name="num2"></param>
/// <returns></returns>
public static int GYS(int num1, int num2)
{
int minNum = Math.Min(num1, num2);
int result = 1;
for (int i = minNum; i > 0; i--)
{
if (num1 % i == 0 && num2 % i == 0)
{
result = i;
break;
}
}
return result;
}
/// <summary>
/// 判断能否被3整除
/// </summary>
/// <param name="num1"></param>
/// <returns></returns>
public static bool ZC(int num1)
{
return num1 % 3 == 0;
}