C Exercises: Check whether three given integer values are in the range 20..50 inclusive
8. Triple Range Check 20 to 50
Write a C program that checks if three given integers are in the range of 20 to 50 (inclusive) and returns true if at least one of them is within the range. If none of the integers are within the range, the program returns false.
C Code:
Sample Output:
1 1 1 0
Explanation:
int test(int x, int y, int z) { return (x >= 20 && x <= 50) || (y >= 20 && y <= 50) || (z >= 20 && z <= 50); }
The above function test takes three integer parameters ‘x’, ‘y’, and ‘z’. It checks if at least one of the three integers is in the range of 20 to 50 (inclusive).
If any of the parameters ‘x’, ‘y’, or ‘z’ is greater than or equal to 20 and less than or equal to 50, the function returns 1 (true), indicating that at least one of the numbers is within the specified range. Otherwise, it returns 0 (false), indicating that none of the numbers are within the specified range.
Time complexity and space complexity:
Time complexity: The function performs three comparisons and three logical OR operations, all of which are constant time operations. Therefore, the time complexity of the function is O(1).
Space complexity: The function uses a constant amount of space to store the input parameters and the return value, so the space complexity is also O(1).
Pictorial Presentation:
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C program to check if three integers are within the range 25 to 55, returning true if at least two are within the range.
- Write a C program that checks three numbers and returns true if exactly one is outside the range 20 to 50.
- Write a C program to verify if at least one of three given integers lies strictly between 30 and 45.
- Write a C program to check if all three integers are outside the range 20 to 50 and return false in that case.
C Programming Code Editor:
Previous: Write a C program to check two given integers whether either of them is in the range 100..200 inclusive.
Next: Write a C program to check whether two given integer values are in the range 20..50 inclusive. Return true if 1 or other is in the said range otherwise false.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.