﻿ C# - Check whether 2 integer values are in the range 20..50

# C#: Check whether two given integer values are in the range 20..50 inclusive

## C# Sharp Basic Algorithm: Exercise-16 with Solution

Write a C# Sharp program to check whether two given integer values are in the range 20..50 inclusive. Return true if 1 or other is in the range, otherwise false.

Visual Presentation:

Sample Solution:

C# Sharp Code:

``````using System;

// Namespace declaration
namespace exercises
{
// Class declaration
class Program
{
// Main method - entry point of the program
static void Main(string[] args)
{
// Displaying the results of the 'test' method with different pairs of integers
Console.WriteLine(test(20, 84)); // Output: True
Console.WriteLine(test(14, 50)); // Output: True
Console.WriteLine(test(11, 45)); // Output: True
Console.WriteLine(test(25, 40)); // Output: False
Console.ReadLine();             // Keeping the console window open
}

// Method to test conditions for two integers x and y
public static bool test(int x, int y)
{
// Check if x is less than or equal to 20 OR y is greater than or equal to 50
// OR Check if y is less than or equal to 20 OR x is greater than or equal to 50
// If any of these conditions is true, return true; otherwise, return false
return (x <= 20 || y >= 50) || (y <= 20 || x >= 50);
}
}
}
```
```

Sample Output:

```True
True
True
False```

Flowchart:

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿