Q:

Write a C# Sharp program to check a given array of integers and return true if the specified number of same elements appears at the start and end of the given array

0

Write a C# Sharp program to check a given array of integers and return true if the specified number of same elements appears at the start and end of the given array

Sample Output:

True
False
True

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
namespace exercises
{
   class Program
    {       
        static void Main(string[] args)
        {               
          Console.WriteLine(test(new[] { 3, 7, 5, 5, 3, 7 }, 2)); 
          Console.WriteLine(test(new[] { 3, 7, 5, 5, 3, 7 }, 3)); 
           Console.WriteLine(test(new[] { 3, 7, 5, 5, 3, 7, 5 }, 3)); 
  
        }       
        
       static bool test(int[] numbers, int len)
         {
           int arra_size = numbers.Length;

            for (int i = 0; i < len; i++)
            {
                if (numbers[i] != numbers[arra_size - len + i])
                {
                    return false;
                }
            }

            return true;
         }    
   } 
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now