w3resource

PHP Exercises: Check if one given temperatures is less than 0 and the other is greater than 100

PHP Basic Algorithm: Exercise-13 with Solution

Write a PHP program to check if one given temperatures is less than 0 and the other is greater than 100.

Sample Solution:

PHP Code :

<?php
// Define a function named "test" that takes two parameters: $temp1 and $temp2
function test($temp1, $temp2) 
{
    // Check if $temp1 is less than 0 and $temp2 is greater than 100,
    // or if $temp2 is less than 0 and $temp1 is greater than 100.
    return $temp1 < 0 && $temp2 > 100 || $temp2 < 0 && $temp1 > 100;
}

// Call the test function with arguments 120 and -1, and var_dump the result
var_dump(test(120, -1));

// Call the test function with arguments -1 and 120, and var_dump the result
var_dump(test(-1, 120));

// Call the test function with arguments 2 and 120, and var_dump the result
var_dump(test(2, 120));
?>

Sample Output:

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

Visual Presentation:

PHP Basic Algorithm Exercises: Check if one given temperatures is less than 0 and the other is greater than 100.

Flowchart:

Flowchart: Check if one given temperatures is less than 0 and the other is greater than 100.

PHP Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a PHP program to check if a given string starts with 'C#' or not.
Next: Write a PHP program to check two given integers whether either of them is in the range 100..200 inclusive.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.