- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures

- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces

# C++ Program for the Common Divisors of Two Numbers?

The common divisor of two numbers are the numbers that are divisors of both of them.

For example,

The divisors of 12 are 1, 2, 3, 4, 6, 12.

The divisors of 18are 1, 2, 3, 6, 9, 18.

Thus, the common divisors of 12 and 18 are 1, 2, 3, 6.

The greatest among these is, perhaps unsurprisingly, called the greatest common divisor of 12 and 18. The usual mathematical notation for the greatest common divisor of two integers a and b are denoted by (a, b). Hence, (12, 18) = 6.

The greatest common divisor is important for many reasons. For example, it can be used to calculate the LCM of two numbers, i.e., the smallest positive integer that is a multiple of these numbers. The least common multiple of the numbers a and b can be calculated as ab(a, b).

For example, the least common multiple of 12 and 18 is 12·18(12, 18) =12 · 18.6

Input: a = 10, b = 20 Output: 1 2 5 10 // all common divisors are 1 2 5 10

**Explanation **

Integers that can exactly divide both numbers (without a remainder).

## Example

#include <iostream> using namespace std; int main() { int n1, n2, i; n1=10; n2=20; for(i=1; i <= n1 && i <= n2; ++i) { if(n1%i==0 && n2%i==0) { cout<<i<<"\t"; } } }

- Related Articles
- C++ Program for Common Divisors of Two Numbers?
- Python Program for Common Divisors of Two Numbers
- Java Program for Common Divisors of Two Numbers
- Program to count number of common divisors of two numbers in Python
- Greatest common divisors in Python
- Write a program to calculate the least common multiple of two numbers JavaScript
- Print the kth common factor of two numbers
- Check if sum of divisors of two numbers are same in Python
- Count the number of common divisors of the given strings in C++
- JavaScript Program for find common elements in two sorted arrays
- Python Program for Check if the count of divisors is even or odd
- Count common prime factors of two numbers in C++
- Divisors of n-square that are not divisors of n in C++ Program
- Program to find the common ratio of three numbers in C++
- Function to calculate the least common multiple of two numbers in JavaScript