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 num1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(“Enter 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 if (num1 % i == 0 && num2 % { hcf = i; } } //Present the output to the Person Console.Write(“HCF of {0} and //Console.ReadLine() t |
Output:
I hope this can assist you together with your interview preparation or examination.
Thanks