Advertisement
voldmaks

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

May 22nd, 2022
1,262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Сдвиг_значений_массива
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] array = new int[10];
  14.             int quantityShiftSteps;
  15.             int valueForMove;
  16.  
  17.             for (int i = 0; i < array.Length; i++)
  18.             {
  19.                 array[i] = i+1;
  20.             }
  21.  
  22.             Console.Write("Массив: ");
  23.             foreach (var number in array)
  24.             {
  25.                 Console.Write(number + " ");
  26.             }
  27.  
  28.             Console.Write("\n\nВведите количество шагов сдвига влево: ");
  29.             quantityShiftSteps = Convert.ToInt32(Console.ReadLine());
  30.  
  31.             for (int i = 0; i < quantityShiftSteps; i++)
  32.             {
  33.                 for (int j = 1; j < array.Length; j++)
  34.                 {
  35.                     valueForMove = array[j - 1];
  36.                     array[j - 1] = array[j];
  37.                     array[j] = valueForMove;
  38.                 }
  39.             }
  40.  
  41.             Console.Write("Массив со сдвигом в " + quantityShiftSteps + " шаг/шага/шагов: ");
  42.             foreach (var number in array)
  43.             {
  44.                 Console.Write(number + " ");
  45.             }
  46.  
  47.             Console.WriteLine("\n");
  48.         }
  49.     }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement