Q:

Write a C# Sharp program to shift an element in left direction and return a new array

0

Write a C# Sharp program to shift an element in left direction and return a new array

Sample Output:

New array: 20 -30 -40 50 10

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[] { 10, 20, -30, -40, 50 });            
           Console.Write("New array: ");         
           foreach(var i in item)
            {
               Console.Write(i.ToString()+" ");
            }     
          }               
       static int[] test(int[] numbers)
         {
          int size = numbers.Length;
            int[] shiftNums = new int[size];

            for (int i = 0; i < size; i++)
            {
                shiftNums[i] = numbers[(i + 1) % size];
            }
            return shiftNums;
         }    
   } 
}

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