Advertisement
Carnality

Cyclic shift

Mar 14th, 2022
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using System;
  2.  
  3. namespace IJunior
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Random random = new Random();
  10.             int[] array = new int[30];
  11.             int userInput;
  12.             int temporary;
  13.  
  14.             for (int i = 0; i < array.Length; i++)
  15.             {
  16.                 array[i] = random.Next(0, 100);
  17.                 Console.Write($"{array[i]} ");
  18.             }
  19.  
  20.             Console.WriteLine();
  21.  
  22.             Console.Write("Введите на сколько позиций надо сдвинуть массив: ");
  23.             userInput = Convert.ToInt32(Console.ReadLine());
  24.  
  25.             for (int i = 0; i < userInput; ++i)
  26.             {
  27.                 int firstElement = array[0];
  28.  
  29.                 for (int j = 1; j < array.Length; j++)
  30.                 {
  31.                     array[j - 1] = array[j];
  32.                 }
  33.  
  34.                 array[array.Length - 1] = firstElement;
  35.             }
  36.  
  37.             for (int i = 0; i < array.Length; i++)
  38.             {
  39.                 Console.Write($"{array[i]} ");
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement