Q:

Write a C# Sharp program to create a new array swapping the first and last elements of a given array of integers and length will be least 1

0

Write a C# Sharp program to create a new array swapping the first and last elements of a given array of integers and length will be least 1

Sample Output:

After swapping first and last elements: 13 5 7 9 11 1

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)
        {          
          int[] item = test(new[] { 1, 5, 7, 9, 11, 13 }); 
          Console.Write("After swapping first and last elements: ");         
           foreach(var i in item)
            {
               Console.Write(i.ToString()+" ");
            }               
        }        
       static int[] test(int[] numbers)
          {
           int first = numbers[0];
            numbers[0] = numbers[numbers.Length - 1];
            numbers[numbers.Length - 1] = first;

            return numbers;
          } 
   }
}

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