w3resource

C#: Check whether a given array of integers of length 2, does not contain 15 or 20


C# Sharp Basic Algorithm: Exercise-98 with Solution

Write a C# Sharp program to check if an array of integers with length 2 does not contain 15 or 20.

Visual Presentation:

C# Sharp: Basic Algorithm Exercises - Check whether a given array of integers of length 2, does not contain 15 or 20.

Sample Solution:-

C# Sharp Code:

using System; // Importing the System namespace

namespace exercises // Defining a namespace called 'exercises'
{
    class Program // Defining a class named 'Program'
    {
        static void Main(string[] args) // The entry point of the program
        {         
            // Output the result of the 'test' method with different integer arrays as arguments
            Console.WriteLine(test(new[] { 12, 20 })); // Calling test method with array [12, 20] and displaying the result
            Console.WriteLine(test(new[] { 14, 15 })); // Calling test method with array [14, 15] and displaying the result
            Console.WriteLine(test(new[] { 11, 21 })); // Calling test method with array [11, 21] and displaying the result
        }        

        // Method to check if all elements in the input array are not equal to 15 or 20
        public static bool test(int[] nums)
        {
            // Returning true if all elements in the array are not equal to 15 or 20
            return nums[0] != 15 && nums[0] != 20 && nums[1] != 15 && nums[1] != 20;
        } 
    }
}

Sample Output:

False
False
True

Flowchart:

C# Sharp: Flowchart: Check whether a given array of integers of length 2, does not contain 15 or 20.

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# Sharp program to check whether a given array of integers of length 2, contains 15 or 20.
Next: Write a C# Sharp program to create a new array of integers and length 1 or more. The length of the new array will be double length of the given array and all the elements are 1 except the first  element which is equal to the given array.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

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/csharp-exercises/basic-algo/csharp-basic-algorithm-exercises-98.php