# C# Program to find Common Divisors

You are Here:

## What are Common Divisors?

A number that divides two or more numbers without remainder.

Tips: It is recommended to use our online common divisor calculator for better understanding.

## Examples

The following table provides few examples of common divisors of the given numbers.

NumbersCommon Divisors
4, 61, 2
12, 241, 2, 3, 4, 6, 12
15, 25, 501, 5

## Common Divisors of Two Numbers

In the following example, we will find the common divisors of numbers 12 and 24.

### Example

C# Compiler
using System; namespace myApp { class Program { static void Main(string[] args) { int num1 = 12; int num2 = 24; int i, min; min = (num1 < num2) ? num1 : num2; Console.WriteLine("Common Divisors of {0} and {1}:", num1 , num2); for(i=1; i<=min; i++) { if((num1 % i == 0) && (num2 % i == 0)) Console.Write(i + " "); } } } }

### Output

Common Divisors of 12 and 24: 1 2 3 4 6 12

## Common Divisors of any Two Given Numbers

In the following example, we will find the common divisors of any two given numbers.

### Example

C# Compiler
using System; namespace myApp { class Program { static void Main(string[] args) { int num1, num2, i, min; Console.Write("Enter (int) num1 = "); num1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter (int) num2 = "); num2 = Convert.ToInt32(Console.ReadLine()); min = (num1 < num2) ? num1 : num2; Console.WriteLine("\nCommon Divisors of {0} and {1}:", num1 , num2); for(i=1; i<=min; i++) { if((num1 % i == 0) && (num2 % i == 0)) Console.Write(i + " "); } } } }

### Output

Enter (int) num1 = 5 Enter (int) num2 = 3 Common Divisors of 5 and 3: 1

## Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on C# with examples for quick and easy learning.

We are working to cover every Single Concept in C#.