最大公约数2数 [英] Greatest common divisor 2 number
本文介绍了最大公约数2数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
推荐答案
Google是您的朋友: c#math.gcd
Google is your friend: c# math.gcd
About 329,000 results on Google[^].
using System;
public class Program
{
static int GCD(int a, int b)
{
int Remainder;
while( b != 0 )
{
Remainder = a % b;
a = b;
b = Remainder;
}
return a;
}
static int Main(string[] args)
{
int x, y;
Console.WriteLine("This program allows calculating the GCD");
Console.Write("Value 1: ");
x = int.Parse(Console.ReadLine());
Console.Write("Value 2: ");
y = int.Parse(Console.ReadLine());
Console.Write("\nThe Greatest Common Divisor of ");
Console.WriteLine("{0} and {1} is {2}", x, y, GCD(x, y));
return 0;
}
}
这篇关于最大公约数2数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文