w3resource
C# Sharp Programming Exercises

C# Sharp Basic Algorithm Exercises: 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 said range otherwise false.

Pictorial Presentation:

C# Sharp: Basic Algorithm Exercises - Check whether two given integer values are in the range 20..50 inclusive

Sample Solution:

C# Sharp Code:

using System;

namespace exercises
{
   class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(test(20, 84));
            Console.WriteLine(test(14, 50));
            Console.WriteLine(test(11, 45));
            Console.WriteLine(test(25, 40));
            Console.ReadLine();
        }

        public static bool test(int x, int y)
        {
            return (x <= 20 || y >= 50) || (y <= 20 || x >= 50);
        }
    }
}

Sample Output:

True
True
True
False

Flowchart:

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

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# Sharp 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.
Next: Write a C# Sharp program to check if a string 'yt' appears at index 1 in a given string. If it appears return a string without 'yt' otherwise return the original string.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming