I'm trying to implement the Euclidean Algorithm with user input in a C# snippet as part of my process of learning this language. MVS tells me that there is an error with the if and elif statements and with the end braces of these statements. Now, coming from a pythonic background this seems pretty natural to me, so please help me identify the possible mistakes. Help is much appreciated.
Code:
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();
}
}
}
}