Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Oct 7, 2022, 2:12 AM EDT
using System; namespace LogicalPrograms { class Program { static void Main(string[] args) { int[] oneDimensionalArray = new int[6]; Console.WriteLine("Enter the 1D Array Elements : "); for (int i = 0; i<oneDimensionalArray.Length; i++) { oneDimensionalArray[i] = int.Parse(Console.ReadLine()); } int temp; for (int j = 0; j < oneDimensionalArray.Length - 1; j++) { temp = oneDimensionalArray[0]; oneDimensionalArray[0] = oneDimensionalArray[j + 1]; oneDimensionalArray[j + 1] = temp; } Console.WriteLine("Array Elements After Right Circular Rotation: "); foreach (int num in oneDimensionalArray) { Console.Write(num + " "); } Console.ReadKey(); } } }Output:
Uday DodiyaRank #239 · 10.3K reputationPosted Oct 7, 2022, 2:23 AM EDT
Algorithm
Program In Java
class RotateRight { public static void main(String[] args) { //Initialize array int [] arr = new int [] {1, 2, 3, 4, 5}; //n determine the number of times an array should be rotated. int n = 3; //Displays original array System.out.println("Original array: "); for (int i = 0; i 0; j--){ //Shift element of array by one arr[j] = arr[j-1]; } //Last element of array will be added to the start of array. arr[0] = last; } System.out.println(); //Displays resulting array after rotation System.out.println("Array after right rotation: "); for(int i = 0; i< arr.length; i++){ System.out.print(arr[i] + " "); } } }Output :
Original array:
1 2 3 4 5
Array after right rotation:
3 4 5 1 2
Program In C#
using System; public class RotateRight { public static void Main() { //Initialize array int [] arr = new int [] {1, 2, 3, 4, 5}; //n determine the number of times an array should be rotated. int n = 3; //Displays original array Console.WriteLine("Original array: "); for (int i = 0; i 0; j--){ //Shift element of array by one arr[j] = arr[j-1]; } //Last element of array will be added to the start of array. arr[0] = last; } Console.WriteLine(); //Displays resulting array after rotation Console.WriteLine("Array after right rotation: "); for(int i = 0; i< arr.Length; i++){ Console.Write(arr[i] + " "); } } }Original array:
1 2 3 4 5
Array after right rotation:
3 4 5 1 2