Advertisement
junniorrkaa

Сдвиг значений массива

Oct 23rd, 2024 (edited)
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | Source Code | 0 0
  1. using System;
  2.  
  3. namespace CSLight
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] array = new int[10];
  10.  
  11.             Random random = new Random();
  12.  
  13.             int tempValueElement;
  14.             int lastTempValueElement;
  15.             int userInput;
  16.             int maxNumber = 10;
  17.             int numberZero = 0;
  18.  
  19.             Console.WriteLine("Массив: ");
  20.  
  21.             for (int i = 0; i < array.Length; i++)
  22.             {
  23.                 array[i] = random.Next(maxNumber);
  24.  
  25.                 Console.Write(array[i] + " ");
  26.             }
  27.  
  28.             Console.Write("\n\nУкажите шаг сдвига: ");
  29.  
  30.             userInput = Convert.ToInt32(Console.ReadLine());
  31.  
  32.             for (int i = 0; i < userInput; i++)
  33.             {
  34.                 lastTempValueElement = array[array.Length - 1];  
  35.                 array[array.Length - 1] = array[0];
  36.  
  37.                 for (int j = array.Length - 1; j > numberZero; j--)
  38.                 {
  39.                     tempValueElement = lastTempValueElement;
  40.                     lastTempValueElement = array[j - 1];
  41.                     array[j - 1] = tempValueElement;
  42.                 }
  43.             }
  44.  
  45.             foreach (int element  in array)
  46.             {
  47.                 Console.Write(element + " ");
  48.             }
  49.  
  50.             Console.WriteLine("\n");
  51.             Console.ReadKey();
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement