PHP Online Compiler
Example: Find LCM of Two Numbers in PHP using For loop
C
C++
C#
Java
Python
PHP
main.php
STDIN
Run
<?php // Find LCM of Two Numbers in PHP using For loop $p = 175; $q = 185; $x = 0; $g = 0; // $p & $q - To store the two positive numbers // $x - To store the LCM number // $g - To store the GCD for ($i = 1; $i <= $p && $i <= $q; $i++) { if ($p % $i == 0 && $q % $i == 0) $g = $i; } $x = ($p * $q) / $g; echo "The LCM of two positive numbers {$p} & {$q} is {$x}."; ?>
Output
Clear
ADVERTISEMENTS