Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Find LCM and GCD: Write a PHP function to find the least common multiple (LCM) and greatest common divisor (GCD) of two numbers.

function findLCM($a, $b) {
    return ($a * $b) / gcd($a, $b);
}

function gcd($a, $b) {
    while ($b != 0) {
        $temp = $b;
        $b = $a % $b;
        $a = $temp;
    }
    return $a;
}

// Example usage:
$num1 = 12;
$num2 = 18;
echo "LCM: " . findLCM($num1, $num2);

Related Posts

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Artificial Intelligence