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:
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 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.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework