Write a PHP program to check which number nearest to the value 100 among two given integers. Return 0 if the two numbers are equal

  • برمجة بي اتش بي

Write a PHP program to check which number nearest to the value 100 among two given integers. Return 0 if the two numbers are equal

الأجوبة

<?php
function test($x, $y) 
{
   $n = 100;
   $val = abs($x - $n);
   $val2 = abs($y - $n);
   return $val == $val2 ? 0 : ($val < $val2 ? $x : $y);
}

echo test(78, 95)."\n";
echo test(95, 95)."\n";
echo test(99, 70)."\n";

Sample Output:

95
0
99
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...