Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Basic Algorithm Exercises: rotate the elements of a given array of integers in left direction and return the new array


C# Sharp Basic Algorithm: Exercise-92 with Solution

Write a C# Sharp program to rotate the elements of a given array of integers (length 4) in left direction and return the new array.

Test Data: 90, 30, 50, 40
Sample Output: Rotated array: 30 50 40 90
Test Data: -40, 10, -20, -10
Sample Output: Rotated array: 10 -20 -10 -40

Pictorial Presentation:

C# Sharp: Basic Algorithm Exercises - Rotate the elements of a given array of integers (length 4 ) in left direction and return the new array.

Sample Solution:-

C# Sharp Code:

using System;
namespace exercises
{
   class Program
    {       
        static void Main(string[] args)
        {
         
           int[] item = test(new[] { 10, 20, -30, -40 }); 
           
           Console.Write("Rotated array: ");
         
           foreach(var i in item)
            {
               Console.Write(i.ToString()+" ");
            }
        }
        
       public static int[]  test(int[] a1)
          {
             return new int[] { a1[1], a1[2], a1[3], a1[0] };
          } 
   }
} 

Sample Output:

Rotated array: 20 -30 -40 10

Flowchart:

C# Sharp: Flowchart: rotate the elements of a given array of integers (length 4) in left direction and return the new arrays.

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# Sharp program to compute the sum of the elements of an given array of integers.
Next: Write a C# Sharp program to reverse a given array of integers and length 4

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.