C# program to find the HCF of two given numbers
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Program:
The source code to find the HCF of two numbers is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
Here, we created a class HcfClass that contains two methods GetHcf() and Main(). In the GetHcf(), we find the highest common factor of two numbers.
In the above code, we checked the common factor of both numbers, the loop executed till the value of counter variable iLoop is less than and equal to anyone of the given number and update the value of the common factor. That's why we loop ends then we have the highest common factor. The GetHcf() method returns the HCF to the calling method.
In the Main() method, we read the values of two integer numbers and then calculated the HCF. Then the HCF is printed on the console screen.