Write an algorithm to find the HCF (Highest Common Factor) of the two numbers entered by a user. Transform your algorithm into a C program, support your program with suitable comments
To find the Highest Common Factor (HCF) of two numbers, we can use the Euclidean algorithm. The algorithm is based on the property that the HCF of two numbers is equal to the HCF of the remainder of the division of the larger number by the smaller number, until the remainder becomes zero. The last non-zero remainder is the HCF of the two numbers.
Here is the algorithm to find the HCF of two numbers:
Read the two numbers from the user and store them in variables num1 and num2.
Initialize a variable remainder to store the remainder.
Initialize a variable temp to store the larger number.
If num2 is greater than num1, swap the values of num1 and num2 so that num1 always contains the larger number.
Perform the following steps until num2 becomes zero:
Calculate the remainder of num1 divided by num2 and
________ ____ ___ _________ ___.
______ _____ ___ _____ ______ ________ ___ ____.
_____ ______ __________ _________ __________ ______ ______ __________.
_________ ____ ___ __________ _________ ___ ____.
___ _____ _________ _________ ______ ____ ________ ________ ____ _____.
__________ ___ __________ _____ __________.
______ ____ ______ _____ ________ __________ ___ ____ __________ __________ __________ __________.
____ ___ ____ _____ _________ __________ _________ _______ __________.
______ _________ ____ __________ ___.
________ _______ __________ _____ ____ ___ ____.
________ __________ ____ __________ __________ ______.
__________ ___ ___ _________ ___.
_________ __________ ____ _______ _____ _______.
___ _________ _________ _______ __________.
______ _______ __________ __________ _______.
_______ ________ __________ __________ ________ _________ _________ __________ ___ __________ ______.
______ ____ ___ ____ _____ ____.
____ __________ _______ ________ _____ ____ _________.
_______ ______ _____ ____ ____ ___ _________ _______ _________.
______ __________ _______ _________ ____.
____ ___ _______ ___ ______ _______ ____ _____ _______ ________.
________ ___ _________ __________ ______.
_______ _____ _____ ___ _____ _______ ______ ___ _________ ______ ______.
__________ _______ __________ ___ _________ _______ _______ __________ _______ ______.
_____ _______ __________ _________ ___ _________ _____ ________.
_________ ________ _________ ____ ___ _____.
_____ _______ ______ _____ _________ _________ __________ _____ ___ ____.
____ _______ ___ _____ _____ ________ _________ ________ ________ ____ ______.
_______ ______ ____ _______ _________ _____ ______ ____ ______ ____.
___ _______ ____ ________ ______ _______.
____ ________ __________ _______ _____ ________ _____ _______ ___ ____.
______ ______ ___ _________ ______ ___ __________.
____ ______ ____ _________ ______.
______ _______ _________ ________ _____ _________ ____.
________ ______ _________ ___ _________ __________ _____ ___ _____ ______ _______.
____ ___ ____ ______ ________ _____ ______ __________ ________ ____ __________ ________.
__________.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required