PHP Practical Slip 8 Q.B

Write a PHP script to define a function Maximum, which will accept 3 numbers as parameters and returns a maximum of 3 numbers.

<?php
// Function to find maximum of 3 numbers
function Maximum($num1, $num2, $num3) {
    $max = $num1; // Assume num1 is maximum initially

    if ($num2 > $max) {
        $max = $num2;
    }
    if ($num3 > $max) {
        $max = $num3;
    }

    return $max;
}

// Example usage
$a = 12;
$b = 45;
$c = 30;

$result = Maximum($a, $b, $c);

// Display result
echo "Numbers: $a, $b, $c<br>";
echo "Maximum Number: " . $result;
?>
Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top