PHP Armstrong NumberPHP Average of N NumbersPHP Biggest of Three NumbersPHP Common DivisorsPHP Composite NumberPHP Condense a NumberPHP Even NumberPHP Factorial of a NumberPHP Fibonacci SeriesPHP GCDPHP LCMPHP Leap YearPHP Multiplication TablePHP Number CombinationPHP Odd NumberPHP Palindrome NumberPHP Perfect NumberPHP Prime FactorPHP Prime NumberPHP Sum of DigitsPHP Swapping Two Numbers

PHP Array ProgramsPHP Converter ProgramsPHP Star Patterns ProgramPHP Number Patterns ProgramPHP Alphabet Patterns ProgramLast Updated:

A largest number that exactly divides two or more integers.

In general, **Greatest Common Divisor** (GCD) is otherwise called as **Greatest Common Factor** (GCF) or **Highest Common Factor** (HCF)

**Tips**: It is recommended to use our online GCD calculator for better understanding.

The following table provides few examples of GCD of the given numbers.

Numbers | GCD |
---|---|

4, 10 | 2 |

6, 5 | 1 |

15, 30 , 45 | 15 |

In the following example, we will find the GCD of the given two numbers (45, 90).

PHP Compiler

<?php
$num1 = 45;
$num2 = 90;
$gcd = 1;
for($i=2; $i<=$num1 && $i<=$num2; $i++)
{
// Checks if i is factor of both integers
if(($num1 % $i == 0) && ($num2 % $i == 0))
$gcd = $i;
}
echo "GCD of $num1 and $num2: $gcd <br>";
?>