我正在尝试使用 C# 代码段中的用户输入来实现欧几里得算法,这是我学习这种语言过程的一部分。MVS 告诉我 if 和 elif 语句以及这些语句的结尾大括号存在错误。现在,来自 pythonic 背景,这对我来说似乎很自然,所以请帮助我找出可能的错误。非常感谢您的帮助。
代码:
namespace EuclideanAlgorithm
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two numbers to calculate their GCD");
int input1 = Convert.ToInt32(Console.ReadLine());
int input2 = Convert.ToInt32(Console.ReadLine());
int remainder;
int a;
int b;
if (input1 == input2);
{
Console.Write("The GCD of", input1, "and", input2, "is", input1);
Console.ReadLine();
}
else if (input1 > input2);
{
a = input1;
b = input2;
while (remainder != 0);
{
remainder = a % b;
a = b;
b = remainder;
}
Console.Write("The GCD of", input1, "and", input2, "is", b);
Console.ReadLine();
}
else if (input1 < input2);
{
a = input2;
b = input1;
while (remainder != 0);
{
remainder = a % b;
a = b;
b = remainder;
}
Console.WriteLine("The GCD of", input1, "and", input2, "is", b);
Console.ReadLine();
}
}
}
}