Q:

Write a PHP program to check three given integers (small, medium and large)

0

Write a PHP program to check three given integers (small, medium and large) and return true if the difference between small and medium and the difference between medium and large is same.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
function test($x, $y, $z)
{
     if ($x > $y && $x > $z && $y > $z) return $x - $y == $y - $z;
     if ($x > $y && $x > $z && $z > $y) return $x - $z == $z - $y;
     if ($y > $x && $y > $z && $x > $z) return $y - $x == $x - $z;
     if ($y > $x && $y > $z && $z > $x) return $y - $z == $z - $x;
     if ($z > $x && $z > $y && $x > $y) return $z - $x == $x - $y;
     return $z - $y == $y - $x;
}

var_dump(test(4, 5, 6));
var_dump(test(7, 12, 13));
var_dump(test(-1, 0, 1));

Sample Output:

bool(true)
bool(false)
bool(true)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now