- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion

# C program to find Highest Common Factor (HCF) and Least Common Multiple (LCM)

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

## 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.

## Least Common Multiple (LCM)

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.

## Example

#include <stdio.h> int main() { int num1, num2, x, y, temp, gcd, lcm; printf("Enter two integers

"); 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

", x, y, gcd); printf("LCM of %d and %d = %d

", x, y, lcm); return 0; }

## Output

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 Articles
- Program to find HCF (Highest Common Factor) of 2 Numbers in C++
- C++ Program to calculate the Highest Common Factor
- Haskell Program to calculate the Highest Common Factor
- How To Search Highest Common Multiple
- Program to find highest common factor of a list of elements in Python
- Find the highest common factor of;$7x^2yz^4, 21x^2y^5z^3$
- Write a program to calculate the least common multiple of two numbers JavaScript
- Finding two numbers given their sum and Highest Common Factor using JavaScript
- Find the greatest common factor (GCF/HCF) of the polynomials $2x^2$ and $12x^2$.
- Find the greatest common factor (GCF/HCF) of the polynomials $x^3$ and $-yx^2$.
- Find the greatest common factor (GCF/HCF) of the polynomials $6x^3y$ and $18x^2y^3$.
- Find the greatest common factor (GCF/HCF) of the polynomial $7x, 21x^2$ and $14xy^2$.
- Find the greatest common factor (GCF/HCF) of the polynomials $15a^3, -45a^2$ and $-150a$.
- Find the greatest common factor (GCF/HCF) of the polynomial $42x^2yz$ and $63x^3y^2z^3$.
- Find the greatest common factor (GCF/HCF) of the polynomials $a^2b^3$ and $a^3b^2$.

Advertisements