PHP Exercises: Check two given integers whether either of them is in the range 100..200 inclusive
PHP Basic Algorithm: Exercise-14 with Solution
Write a PHP program to check two given integers whether either of them is in the range 100..200 inclusive.
Sample Solution:
PHP Code :
<?php
// Define a function named "test" that takes two parameters: $x and $y
function test($x, $y)
{
// Check if $x is between 100 and 200 (inclusive) or if $y is between 100 and 200 (inclusive)
return ($x >= 100 && $x <= 200) || ($y >= 100 && $y <= 200);
}
// Call the test function with arguments 100 and 199, and var_dump the result
var_dump(test(100, 199));
// Call the test function with arguments 250 and 300, and var_dump the result
var_dump(test(250, 300));
// Call the test function with arguments 105 and 190, and var_dump the result
var_dump(test(105, 190));
?>
Sample Output:
bool(true) bool(false) bool(true)
Visual Presentation:
Flowchart:
PHP Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a PHP program to check if one given temperatures is less than 0 and the other is greater than 100.
Next: Write a PHP program to check whether three given integer values are in the range 20..50 inclusive. Return true if 1 or more of them are in the said range otherwise false.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics