using System;
using System.Collections.Generic;
using System.Text;
namespace ExMaxGongYueShu
{
class MaxGongYueShu
{
public float maxGongYueShu(int n1,int n2)
{
int temp = Math.Max(n1, n2);
n2 = Math.Min(n1, n2);//n2中存放两个数中最小的
n1 = temp;//n1中存放两个数中最大的
while(n2!=0)
{
n1 = n1 > n2 ? n1 : n2;//使n1中的数大于n2中的数
int m=n1 % n2;
n1 = n2;
n2 = m;
}
return n1;
}
static void Main(string[] args)
{
int n1=Convert.ToInt32 (Console.ReadLine());
int n2 = Convert.ToInt32(Console.ReadLine());
if (n1 * n2 != 0)
{
MaxGongYueShu m = new MaxGongYueShu();
Console.WriteLine(m.maxGongYueShu(n1, n2));
}
else
{
Console.WriteLine("这两个数不能为0。");
}
}
}
}
|
请发表评论