C# Program to Find HCF of two Numbers
In this C# program, we will take the input from the user and find HCF of two numbers.
C# program to Find HCF of two Numbers Code:
private static void Main(string[] args)
{
int n1, n2, i, hcf = 0;
Console.Write("Enter first number : ");
n1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter second number : ");
n2 = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= n1 || i <= n2; i++)
{
if (n1 % i == 0 && n2 % i == 0)
hcf = i;
}
Console.WriteLine("HCF of {0} and {1} is {2}", n1, n2, hcf);
Console.ReadLine();
}
C# program to Find HCF of two Numbers Output: