...

/

Finding the Highest Common Factor

Finding the Highest Common Factor

Learn to find the highest common factor for two numbers in Ruby.

We'll cover the following...

Problem

Write a program that asks the user to enter two non-negative integers and find their highest common factor (HCF).

Enter the first number: (8)
Enter the second number: (12)
The HCF of 8 and 12 is: 4
Calculating HCF of two numbers

The largest common factor of two or more numbers is called the highest common factor. The HCF is also known as the greatest common divisor (GCD).

For example,

8=18 = 1 ×\times 8=28 = 2 ×\times ...