- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

First, let us learn how to find Highest Common Factor (HCF).

The greatest number divides each of the two or more numbers is called HCF or Highest Common Factor. It is also called as Greatest Common Measure(GCM) and Greatest Common Divisor(GCD).

For example,

**What is the HCF of 12 and 16?**

Factors of 12 = 1, 2, 3, 4, 6,12. Factors of 16=1,2,4,8,16

Highest common factor (H.C.F) of 12 and 16 = 4.

For two integers x and y, denoted LCM(x,y), it is the smallest positive integer that is divisible by both x and y.

For example,

LCM(2,3) = 6 and LCM(6,10) = 30.

#include <stdio.h> int main() { int num1, num2, x, y, temp, gcd, lcm; printf("Enter two integers\n"); scanf("%d%d", &x, &y); num1 = x; num2 = y; while (num2 != 0) { temp = num2; num2 = num1 % num2; num1 = temp; } gcd = num1; lcm = (x*y)/gcd; printf("GCD of %d and %d = %d\n", x, y, gcd); printf("LCM of %d and %d = %d\n", x, y, lcm); return 0; }

Upon execution, you will receive the following output −

Run 1: Enter two integers 6 12 GCD of 6 and 12 = 6 LCM of 6 and 12 = 12 Run 2: Enter two integers 24 36 GCD of 24 and 36 = 12 LCM of 24 and 36 = 72

- Related Questions & Answers
- Program to find HCF (Highest Common Factor) of 2 Numbers in C++
- Finding two numbers given their sum and Highest Common Factor using JavaScript
- Write a program to calculate the least common multiple of two numbers JavaScript
- Find the other number when LCM and HCF given in C++
- Largest Component Size by Common Factor in C++
- Function to calculate the least common multiple of two numbers in JavaScript
- Calculating least common of a range JavaScript
- Finding the least common multiple of a range of numbers in JavaScript?
- C# program to check if two lists have at-least one element common
- C++ Program to Find LCM
- Common element with least index sum in JavaScript
- Print the kth common factor of two numbers
- C# program to find common elements in three sorted arrays
- Program to find length of longest common subsequence in C++
- Program to find length of longest common substring in C++

Advertisements