TheBulgarianWolf

Array Rotation

Oct 14th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.CodeAnalysis;
  4. using System.Linq;
  5. using System.Numerics;
  6.  
  7. namespace SoftuniExercisesWithVariables
  8. {
  9.     class Program
  10.     {
  11.        
  12.  
  13.         static void Main(string[] args)
  14.         {
  15.  
  16.             Console.WriteLine("Enter your array here: ");
  17.             int[] array = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
  18.             Console.WriteLine("Enter number of changes you want:  ");
  19.             int changes = int.Parse(Console.ReadLine());
  20.            
  21.             while(changes>0)
  22.             {
  23.                 int temp = array[0];
  24.                 for (int i = 0; i < array.Length-1; i++)
  25.                 {
  26.                     array[i] = array[i + 1];
  27.                 }
  28.                 array[array.Length - 1] = temp;
  29.                 changes--;
  30.             }
  31.             foreach(int i in array)
  32.             {
  33.                 Console.Write(i + " ");
  34.             }
  35.            
  36.            
  37.         }
  38.     }
  39. }
  40.  
Add Comment
Please, Sign In to add comment