Wednesday, August 14, 2024
HomeC#Program to seek out the HCF of two numbers in C# ~...

# Program to seek out the HCF of two numbers in C# ~ IT Tutorials with Instance

On this weblog, we are going to be taught discover the HCF of two numbers in C#. If you’re on the lookout for Packages requested in C# Interview, test the beneath hyperlink:

HCF
Stands for Highest Frequent Issue. It’s also known as the Biggest Frequent Measure (GCM) and Biggest Frequent Divisor (GCD). For locating the HCF, we have to discover the best quantity which divides two or extra numbers.

Verify the beneath C# program, for calculating the HCF of two numbers in C#. I’ve talked about feedback as effectively for straightforward understanding.

 int num1, num2, loopCheck, hcf=0; //Immediate consumer so as to add two quantity for which HCF wants to seek out Console.WriteLine(“Enter First Quantity”); num1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(“Enter Second Quantity”); num2 = Convert.ToInt32(Console.ReadLine()); //set the min worth out of the numbers entered by the consumer loopCheck = num2 > num1 ? num1 : num2; //Loop the info from 1 to the loopCheck worth for (int i = 1; i <= loopCheck; i++) {     //If Modulus of each quantity can be Zero than retailer it in hcf variable     if (num1 % i == 0 && num2 % i == 0)     {         hcf = i;     } } //Present the output to the Person Console.Write(“HCF of {0} and {1} is: {2}”, num1, num2, hcf); //Console.ReadLine() t

Output:

I hope this can assist you together with your interview preparation or examination.

Thanks

RELATED ARTICLES