HCFWrite a program to find out the Highest Common Factor for given two numbers.Constraints:NAExample:Sample Input:12 30Sample Output:6Explanation:Highest common factor for 12 and 30 is 6 . So the output is 6
Question
HCFWrite a program to find out the Highest Common Factor for given two numbers.Constraints:NAExample:Sample Input:12 30Sample Output:6Explanation:Highest common factor for 12 and 30 is 6 . So the output is 6
Solution
Sure, here is a simple program to find the Highest Common Factor (HCF) of two numbers. This program is written in Python.
# Function to find HCF
def compute_hcf(x, y):
while(y):
x, y = y, x % y
return x
num1 = 12
num2 = 30
print("The HCF is", compute_hcf(num1, num2))
In this program, we define a function compute_hcf(x, y) that uses a while loop to compute the HCF. The while loop continues until y becomes 0. In each iteration, the value of x is updated to y and y is updated to x % y.
Then we define two variables num1 and num2 with the values 12 and 30 respectively. We call the compute_hcf function with num1 and num2 as arguments and print the result. The output of this program will be The HCF is 6.
Similar Questions
HCFWrite a program to find out the Highest Common Factor for given two numbers.
Write a program to find out the Highest Common Factor for given two numbers.
Find the highest common factor (HCF) of 32 and 120.
Find the Highest Common Factor (HCF) of 147 and 70.
Greatest Common Factor
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.