C++ Exercises: Check two given integers whether either of them is in the range 100..200 inclusive
C++ Basic Algorithm: Exercise-14 with Solution
Check if Integers are in Range 100–200
Write a C++ program to check two given integers whether either of them is in the range 100..200 inclusive.
Sample Solution:
C++ Code :
#include <iostream>
using namespace std;
// Function to check if either of the two integers falls within the range 100 to 200 (inclusive)
bool test(int x, int y)
{
// Check if either x or y is within the range 100 to 200
return (x >= 100 && x <= 200) || (y >= 100 && y <= 200);
}
// Main function
int main()
{
cout << test(100, 199) << endl; // Output the result of test function with values 100 and 199
cout << test(250, 300) << endl; // Output the result of test function with values 250 and 300
cout << test(105, 190) << endl; // Output the result of test function with values 105 and 190
return 0; // Return 0 to indicate successful execution of the program
}
Sample Output:
1 0 1
Visual Presentation:
Flowchart:
C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a C++ program to check if one given temperatures is less than 0 and the other is greater than 100.
Next: Write a C++ 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?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/cpp-exercises/basic-algorithm/cpp-basic-algorithm-exercise-14.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics